|
@@ -632,12 +632,14 @@ extension String {
|
|
|
let font = UIFont.systemFont(ofSize: 12)
|
|
|
let boldFont = UIFont.boldSystemFont(ofSize: 12)
|
|
|
let italicFont = UIFont.italicSystemFont(ofSize: 12)
|
|
|
+ let boldItalicFont = UIFont.systemFont(ofSize: 12, weight: .semibold)
|
|
|
let textUTF8 = String(self.utf8)
|
|
|
let finalText = NSMutableAttributedString(string: textUTF8, attributes: [NSAttributedString.Key.font: font])
|
|
|
let boldSign: Character = "*"
|
|
|
let italicSign: Character = "_"
|
|
|
let underlineSign: Character = "^"
|
|
|
let strikethroughSign: Character = "~"
|
|
|
+ var locationBold: [NSRange] = []
|
|
|
|
|
|
//Bold
|
|
|
let rangeBold = getRangeOfWordWithSign(sentence: textUTF8, sign: boldSign)
|
|
@@ -668,6 +670,7 @@ extension String {
|
|
|
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
|
|
|
+ locationBold.append(NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
finalText.addAttribute(.font, value: boldFont, 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))
|
|
@@ -712,7 +715,11 @@ extension String {
|
|
|
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: italicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
+ if isIntInRangeList((rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange - lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, rangeList: locationBold) {
|
|
|
+ finalText.addAttribute(.font, value: boldItalicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
+ } else {
|
|
|
+ finalText.addAttribute(.font, value: italicFont, 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))
|
|
@@ -847,6 +854,15 @@ extension String {
|
|
|
return finalText
|
|
|
}
|
|
|
|
|
|
+ func isIntInRangeList(_ intValue: Int, rangeList: [NSRange]) -> Bool {
|
|
|
+ for range in rangeList {
|
|
|
+ if intValue >= range.location && intValue < range.location + range.length {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
func checkCharBefore(char: String) -> Bool {
|
|
|
return char == " " || char == "\n"
|
|
|
}
|