|
@@ -640,12 +640,12 @@ extension String {
|
|
|
//Bold
|
|
|
let rangeBold = getRangeOfWordWithSign(sentence: textUTF8, sign: boldSign)
|
|
|
if rangeBold.count > 0 {
|
|
|
- var lastFirstRange = 0
|
|
|
+ var lastFirstRange = -1
|
|
|
var countRemoveBoldSign = 0
|
|
|
var continueCheckingBold = false
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeBold.count {
|
|
|
- if lastFirstRange == 0 {
|
|
|
+ if lastFirstRange == -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
|
|
@@ -656,6 +656,12 @@ extension String {
|
|
|
if !continueCheckingBold {
|
|
|
continue
|
|
|
}
|
|
|
+ if rangeBold[i].endIndex != (textUTF8.count-1) {
|
|
|
+ let char: Character = Array(textUTF8.substring(from: rangeBold[i].endIndex + 1, to: rangeBold[i].endIndex + 1))[0]
|
|
|
+ if char.isLetter || char.isNumber {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
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
|
|
@@ -668,7 +674,7 @@ extension String {
|
|
|
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
|
|
|
+ lastFirstRange = -1
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -676,12 +682,12 @@ extension String {
|
|
|
let textAfterbold = finalText.string
|
|
|
let rangeItalic = getRangeOfWordWithSign(sentence: textAfterbold, sign: italicSign)
|
|
|
if rangeItalic.count > 0 {
|
|
|
- var lastFirstRange = 0
|
|
|
+ var lastFirstRange = -1
|
|
|
var countRemoveItalicSign = 0
|
|
|
var continueCheckingItalic = false
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeItalic.count {
|
|
|
- if lastFirstRange == 0 {
|
|
|
+ if lastFirstRange == -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
|
|
@@ -692,6 +698,12 @@ extension String {
|
|
|
if !continueCheckingItalic {
|
|
|
continue
|
|
|
}
|
|
|
+ if rangeItalic[i].endIndex != (textUTF8.count-1) {
|
|
|
+ let char: Character = Array(textUTF8.substring(from: rangeItalic[i].endIndex + 1, to: rangeItalic[i].endIndex + 1))[0]
|
|
|
+ if char.isLetter || char.isNumber {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
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
|
|
@@ -704,7 +716,7 @@ extension String {
|
|
|
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
|
|
|
+ lastFirstRange = -1
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -712,12 +724,12 @@ extension String {
|
|
|
let textAfterItalic = finalText.string
|
|
|
let rangeUnderline = getRangeOfWordWithSign(sentence: textAfterItalic, sign: underlineSign)
|
|
|
if rangeUnderline.count > 0 {
|
|
|
- var lastFirstRange = 0
|
|
|
+ var lastFirstRange = -1
|
|
|
var countRemoveUnderlineSign = 0
|
|
|
var continueCheckingUnderline = false
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeUnderline.count {
|
|
|
- if lastFirstRange == 0 {
|
|
|
+ if lastFirstRange == -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
|
|
@@ -728,6 +740,12 @@ extension String {
|
|
|
if !continueCheckingUnderline {
|
|
|
continue
|
|
|
}
|
|
|
+ if rangeUnderline[i].endIndex != (textUTF8.count-1) {
|
|
|
+ let char: Character = Array(textUTF8.substring(from: rangeUnderline[i].endIndex + 1, to: rangeUnderline[i].endIndex + 1))[0]
|
|
|
+ if char.isLetter || char.isNumber {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
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
|
|
@@ -740,7 +758,7 @@ extension String {
|
|
|
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
|
|
|
+ lastFirstRange = -1
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -748,12 +766,12 @@ extension String {
|
|
|
let textAfterUnderline = finalText.string
|
|
|
let rangeStrikethrough = getRangeOfWordWithSign(sentence: textAfterUnderline, sign: strikethroughSign)
|
|
|
if rangeStrikethrough.count > 0 {
|
|
|
- var lastFirstRange = 0
|
|
|
+ var lastFirstRange = -1
|
|
|
var countRemoveStrikethroughSign = 0
|
|
|
var continueCheckingStrikethrough = false
|
|
|
var totalEmoji = 0
|
|
|
for i in 0..<rangeStrikethrough.count {
|
|
|
- if lastFirstRange == 0 {
|
|
|
+ if lastFirstRange == -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
|
|
@@ -764,6 +782,12 @@ extension String {
|
|
|
if !continueCheckingStrikethrough {
|
|
|
continue
|
|
|
}
|
|
|
+ if rangeStrikethrough[i].endIndex != (textUTF8.count-1) {
|
|
|
+ let char: Character = Array(textUTF8.substring(from: rangeStrikethrough[i].endIndex + 1, to: rangeStrikethrough[i].endIndex + 1))[0]
|
|
|
+ if char.isLetter || char.isNumber {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
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
|
|
@@ -776,7 +800,7 @@ extension String {
|
|
|
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
|
|
|
+ lastFirstRange = -1
|
|
|
}
|
|
|
}
|
|
|
|