mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Fix string indexing
This commit is contained in:
parent
b5f54de5a9
commit
6a7233ed05
@ -218,13 +218,16 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
|
|||||||
}
|
}
|
||||||
|
|
||||||
let paragraphBreak = "\n"
|
let paragraphBreak = "\n"
|
||||||
|
|
||||||
|
var nsString = string.string as NSString
|
||||||
|
var stringLength = nsString.length
|
||||||
|
|
||||||
let paragraphRange: NSRange
|
let paragraphRange: NSRange
|
||||||
if range.lowerBound == 0 {
|
if range.lowerBound == 0 {
|
||||||
paragraphRange = NSRange(location: range.lowerBound, length: range.upperBound - range.lowerBound)
|
paragraphRange = NSRange(location: range.lowerBound, length: range.upperBound - range.lowerBound)
|
||||||
} else if string.string[string.string.index(string.string.startIndex, offsetBy: range.lowerBound)] == "\n" {
|
} else if nsString.character(at: range.lowerBound) == 0x0a {
|
||||||
paragraphRange = NSRange(location: range.lowerBound + 1, length: range.upperBound - range.lowerBound - 1)
|
paragraphRange = NSRange(location: range.lowerBound + 1, length: range.upperBound - range.lowerBound - 1)
|
||||||
} else if string.string[string.string.index(string.string.startIndex, offsetBy: range.lowerBound - 1)] == "\n" {
|
} else if nsString.character(at: range.lowerBound - 1) == 0x0a {
|
||||||
paragraphRange = NSRange(location: range.lowerBound, length: range.upperBound - range.lowerBound)
|
paragraphRange = NSRange(location: range.lowerBound, length: range.upperBound - range.lowerBound)
|
||||||
} else {
|
} else {
|
||||||
string.insert(NSAttributedString(string: paragraphBreak), at: range.lowerBound)
|
string.insert(NSAttributedString(string: paragraphBreak), at: range.lowerBound)
|
||||||
@ -234,8 +237,11 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
|
|||||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(id: nextBlockId, title: nil, color: baseQuoteTintColor), range: paragraphRange)
|
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(id: nextBlockId, title: nil, color: baseQuoteTintColor), range: paragraphRange)
|
||||||
nextBlockId += 1
|
nextBlockId += 1
|
||||||
|
|
||||||
if string.string.index(string.string.startIndex, offsetBy: paragraphRange.upperBound) != string.string.endIndex {
|
nsString = string.string as NSString
|
||||||
if string.string[string.string.index(string.string.startIndex, offsetBy: paragraphRange.upperBound)] == "\n" {
|
stringLength = nsString.length
|
||||||
|
|
||||||
|
if paragraphRange.upperBound < stringLength {
|
||||||
|
if nsString.character(at: paragraphRange.upperBound) == 0x0a {
|
||||||
string.replaceCharacters(in: NSMakeRange(paragraphRange.upperBound, 1), with: "")
|
string.replaceCharacters(in: NSMakeRange(paragraphRange.upperBound, 1), with: "")
|
||||||
rangeOffset -= 1
|
rangeOffset -= 1
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user