We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App crashed when the text of UILabel is come from network data parse.May be caused by string encoding. I simulated the scene with SwiftPlayground.
let key = "天" let text = String(data: "明天开始".data(using: .unicode)!, encoding: .unicode)! let ranges = text.lowercased().ranges(of: key) print("matchedRanges: \(ranges)") // matchedRanges: [Range(Swift.String.Index(_rawBits: 196608)..<Swift.String.Index(_rawBits: 393216))] print("originText.endIndex: \(text.endIndex)") // originText.endIndex: Index(_rawBits: 262144) print("lowercased.endIndex: \(text.lowercased().endIndex)") // lowercased.endIndex: Index(_rawBits: 786432)
The upperBound of matched range is greater than the originText.endIndex.
Remove the lowercased option before match range and use CompareOptions.caseInsensitive as the default value of ranges method.
CompareOptions.caseInsensitive
ranges
I am happy to submit PR if you allow it.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Problem
App crashed when the text of UILabel is come from network data parse.May be caused by
string encoding. I simulated the scene with SwiftPlayground.
The upperBound of matched range is greater than the originText.endIndex.
Solution
Remove the lowercased option before match range and use
CompareOptions.caseInsensitive
as the default value ofranges
method.The text was updated successfully, but these errors were encountered: