|
@@ -646,7 +646,7 @@ extension String {
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeBold.count {
|
|
|
if lastFirstRange == 0 {
|
|
|
- if (rangeBold[i].startIndex == 0 || checkCharBeforeAfter(char: textUTF8.substring(from: rangeBold[i].startIndex - 1, to: rangeBold[i].startIndex - 1))) {
|
|
|
+ if (rangeBold[i].startIndex == 0 || checkCharBefore(char: textUTF8.substring(from: rangeBold[i].startIndex - 1, to: rangeBold[i].startIndex - 1))) {
|
|
|
lastFirstRange = rangeBold[i].startIndex
|
|
|
continueCheckingBold = true
|
|
|
} else {
|
|
@@ -656,21 +656,19 @@ extension String {
|
|
|
if !continueCheckingBold {
|
|
|
continue
|
|
|
}
|
|
|
- if (rangeBold[i].endIndex == textUTF8.count - 1 || checkCharBeforeAfter(char: textUTF8.substring(from: rangeBold[i].endIndex + 1, to: rangeBold[i].endIndex + 1))) {
|
|
|
- let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveBoldSign)).countEmojiCharacter()
|
|
|
- let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveBoldSign), to: rangeBold[i].endIndex - (2*countRemoveBoldSign)).countEmojiCharacter()
|
|
|
- totalEmoji = countEmoji + countEmojiBefore
|
|
|
- finalText.addAttribute(.font, value: font.bold, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
- if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveBoldSign), length: 1))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: rangeBold[i].endIndex + totalEmoji - (2*countRemoveBoldSign) - 1, length: 1))
|
|
|
- countRemoveBoldSign += 1
|
|
|
- } else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeBold[i].endIndex + totalEmoji, length: 1))
|
|
|
- }
|
|
|
- lastFirstRange = 0
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveBoldSign)).countEmojiCharacter()
|
|
|
+ let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveBoldSign), to: rangeBold[i].endIndex - (2*countRemoveBoldSign)).countEmojiCharacter()
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.font, value: font.bold, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
+ if !isEditing{
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveBoldSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: rangeBold[i].endIndex + totalEmoji - (2*countRemoveBoldSign) - 1, length: 1))
|
|
|
+ countRemoveBoldSign += 1
|
|
|
+ } else {
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeBold[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
+ lastFirstRange = 0
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -684,7 +682,7 @@ extension String {
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeItalic.count {
|
|
|
if lastFirstRange == 0 {
|
|
|
- if (rangeItalic[i].startIndex == 0 || checkCharBeforeAfter(char: textAfterbold.substring(from: rangeItalic[i].startIndex - 1, to: rangeItalic[i].startIndex - 1))) {
|
|
|
+ if (rangeItalic[i].startIndex == 0 || checkCharBefore(char: textAfterbold.substring(from: rangeItalic[i].startIndex - 1, to: rangeItalic[i].startIndex - 1))) {
|
|
|
lastFirstRange = rangeItalic[i].startIndex
|
|
|
continueCheckingItalic = true
|
|
|
} else {
|
|
@@ -694,21 +692,19 @@ extension String {
|
|
|
if !continueCheckingItalic {
|
|
|
continue
|
|
|
}
|
|
|
- if (rangeItalic[i].endIndex == textAfterbold.count - 1 || checkCharBeforeAfter(char: textAfterbold.substring(from: rangeItalic[i].endIndex + 1, to: rangeItalic[i].endIndex + 1))) {
|
|
|
- let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveItalicSign)).countEmojiCharacter()
|
|
|
- let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveItalicSign), to: rangeItalic[i].endIndex - (2*countRemoveItalicSign)).countEmojiCharacter()
|
|
|
- totalEmoji = countEmoji + countEmojiBefore
|
|
|
- finalText.addAttribute(.font, value: font.italic, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
- if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveItalicSign), length: 1))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji - (2*countRemoveItalicSign) - 1, length: 1))
|
|
|
- countRemoveItalicSign += 1
|
|
|
- } else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji, length: 1))
|
|
|
- }
|
|
|
- lastFirstRange = 0
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveItalicSign)).countEmojiCharacter()
|
|
|
+ let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveItalicSign), to: rangeItalic[i].endIndex - (2*countRemoveItalicSign)).countEmojiCharacter()
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.font, value: font.italic, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
+ if !isEditing{
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveItalicSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji - (2*countRemoveItalicSign) - 1, length: 1))
|
|
|
+ countRemoveItalicSign += 1
|
|
|
+ } else {
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
+ lastFirstRange = 0
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -722,7 +718,7 @@ extension String {
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeUnderline.count {
|
|
|
if lastFirstRange == 0 {
|
|
|
- if (rangeUnderline[i].startIndex == 0 || checkCharBeforeAfter(char: textAfterItalic.substring(from: rangeUnderline[i].startIndex - 1, to: rangeUnderline[i].startIndex - 1))) {
|
|
|
+ if (rangeUnderline[i].startIndex == 0 || checkCharBefore(char: textAfterItalic.substring(from: rangeUnderline[i].startIndex - 1, to: rangeUnderline[i].startIndex - 1))) {
|
|
|
lastFirstRange = rangeUnderline[i].startIndex
|
|
|
continueCheckingUnderline = true
|
|
|
} else {
|
|
@@ -732,21 +728,19 @@ extension String {
|
|
|
if !continueCheckingUnderline {
|
|
|
continue
|
|
|
}
|
|
|
- if (rangeUnderline[i].endIndex == textAfterItalic.count - 1 || checkCharBeforeAfter(char: textAfterItalic.substring(from: rangeUnderline[i].endIndex + 1, to: rangeUnderline[i].endIndex + 1))) {
|
|
|
- let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveUnderlineSign)).countEmojiCharacter()
|
|
|
- let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveUnderlineSign), to: rangeUnderline[i].endIndex - (2*countRemoveUnderlineSign)).countEmojiCharacter()
|
|
|
- totalEmoji = countEmoji + countEmojiBefore
|
|
|
- finalText.addAttribute(.underlineStyle, value: NSUnderlineStyle.thick.rawValue, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign) + countEmojiBefore + 1, length: (rangeUnderline[i].endIndex + countEmoji - 1) - lastFirstRange))
|
|
|
- if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveUnderlineSign), length: 1))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji - (2*countRemoveUnderlineSign) - 1, length: 1))
|
|
|
- countRemoveUnderlineSign += 1
|
|
|
- } else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji, length: 1))
|
|
|
- }
|
|
|
- lastFirstRange = 0
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveUnderlineSign)).countEmojiCharacter()
|
|
|
+ let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveUnderlineSign), to: rangeUnderline[i].endIndex - (2*countRemoveUnderlineSign)).countEmojiCharacter()
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.underlineStyle, value: NSUnderlineStyle.thick.rawValue, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign) + countEmojiBefore + 1, length: (rangeUnderline[i].endIndex + countEmoji - 1) - lastFirstRange))
|
|
|
+ if !isEditing{
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveUnderlineSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji - (2*countRemoveUnderlineSign) - 1, length: 1))
|
|
|
+ countRemoveUnderlineSign += 1
|
|
|
+ } else {
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
+ lastFirstRange = 0
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -760,7 +754,7 @@ extension String {
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeStrikethrough.count {
|
|
|
if lastFirstRange == 0 {
|
|
|
- if (rangeStrikethrough[i].startIndex == 0 || checkCharBeforeAfter(char: textAfterUnderline.substring(from: rangeStrikethrough[i].startIndex - 1, to: rangeStrikethrough[i].startIndex - 1))) {
|
|
|
+ if (rangeStrikethrough[i].startIndex == 0 || checkCharBefore(char: textAfterUnderline.substring(from: rangeStrikethrough[i].startIndex - 1, to: rangeStrikethrough[i].startIndex - 1))) {
|
|
|
lastFirstRange = rangeStrikethrough[i].startIndex
|
|
|
continueCheckingStrikethrough = true
|
|
|
} else {
|
|
@@ -770,21 +764,19 @@ extension String {
|
|
|
if !continueCheckingStrikethrough {
|
|
|
continue
|
|
|
}
|
|
|
- if (rangeStrikethrough[i].endIndex == textAfterUnderline.count - 1 || checkCharBeforeAfter(char: textAfterUnderline.substring(from: rangeStrikethrough[i].endIndex + 1, to: rangeStrikethrough[i].endIndex + 1))) {
|
|
|
- let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
|
|
|
- let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveStrikethroughSign), to: rangeStrikethrough[i].endIndex - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
|
|
|
- totalEmoji = countEmoji + countEmojiBefore
|
|
|
- finalText.addAttribute(.strikethroughStyle, value: 2, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign) + countEmojiBefore + 1, length: (rangeStrikethrough[i].endIndex + countEmoji - 1) - lastFirstRange))
|
|
|
- if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveStrikethroughSign), length: 1))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji - (2*countRemoveStrikethroughSign) - 1, length: 1))
|
|
|
- countRemoveStrikethroughSign += 1
|
|
|
- } else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji, length: 1))
|
|
|
- }
|
|
|
- lastFirstRange = 0
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
|
|
|
+ let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveStrikethroughSign), to: rangeStrikethrough[i].endIndex - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.strikethroughStyle, value: 2, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign) + countEmojiBefore + 1, length: (rangeStrikethrough[i].endIndex + countEmoji - 1) - lastFirstRange))
|
|
|
+ if !isEditing{
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveStrikethroughSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji - (2*countRemoveStrikethroughSign) - 1, length: 1))
|
|
|
+ countRemoveStrikethroughSign += 1
|
|
|
+ } else {
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
+ lastFirstRange = 0
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -842,7 +834,7 @@ extension String {
|
|
|
return finalText
|
|
|
}
|
|
|
|
|
|
- func checkCharBeforeAfter(char: String) -> Bool {
|
|
|
+ func checkCharBefore(char: String) -> Bool {
|
|
|
return char == " " || char == "\n"
|
|
|
}
|
|
|
|