\r\n is one Character


#1

"\r\n" is a single Character. Is this the correct behaviour?


(Joe Groff) #2

Yes, a Character corresponds to a Unicode grapheme cluster, and "\r\n" is considered a single grapheme cluster.

-Joe

···

On Jan 27, 2016, at 7:52 PM, Darren Mo via swift-users <swift-users@swift.org> wrote:

"\r\n" is a single Character. Is this the correct behaviour?


(Zhao Xin) #3

​For a new line, Unix uses LF, Classic Mac uses ​CR, Windows uses CRLF.
They both means the CR in Unicode.

let str = "\r\n"

str.characters.count // 1

str.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) // 2

str.unicodeScalars.first!.value // 13

zhaoxin

···

On Thu, Jan 28, 2016 at 11:52 AM, Darren Mo via swift-users < swift-users@swift.org> wrote:

"\r\n" is a single Character. Is this the correct behaviour?

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


#4

Thanks, Joe. Found it at http://www.unicode.org/reports/tr29/#GB3.

···

On Jan 28, 2016, at 1:56 PM, Joe Groff <jgroff@apple.com> wrote:

On Jan 27, 2016, at 7:52 PM, Darren Mo via swift-users <swift-users@swift.org> wrote:

"\r\n" is a single Character. Is this the correct behaviour?

Yes, a Character corresponds to a Unicode grapheme cluster, and "\r\n" is considered a single grapheme cluster.

-Joe