btnguyen2k / swiftutils

Utility library in Swift
MIT License
72 stars 23 forks source link

fix string length calculate issue with unicode #10

Closed iceboxi closed 5 years ago

iceboxi commented 5 years ago

fix unicode string count issue for example, input string as

let test = """
-----BEGIN PUBLIC KEY-----\r\ntest\r\n-----END PUBLIC KEY-----
"""

test.count will be 56 in this case, regExp.stringByReplacingMatches result will be

test-----ENDPUBLICKEY-----

but correct count should be test.lengthOfBytes(using: .utf8) = 58 and regExp.stringByReplacingMatches result will be

test
btnguyen2k commented 5 years ago

Thanks @iceboxi , PR has been merged.

Cheers, Thanh Nguyen