Represents a Unicode character.
Represents a Unicode character. Internally, it maintains both codepoint
and UTF-8 representations. Conversion from native Char to UChar is
val ch: UChar = 'c'
A UObject can convert itself to UString
High-performance string with internal UTF-8 encoding.
High-performance string with internal UTF-8 encoding. Conveniently use
interpolator U to create instances of UString.
val myString = U"This is my string" // type of myString is UString
Conversion from native String to UString is provided implicitly.
val myString: UString = "This is my string"
The philosophy behind this class is that, more often than not, text data is
stored and read in UTF-8 encoding, and written to output with little or no
processing. Most often such process can be done at byte level (such as
concatenation), and in cases when iteration of code points is required, it
can be done directly over the UTF-8 stream. By avoiding unnecessary encoding and
decoding to and from UTF-8, unlike Java String, we can save our CPU
resources. Also since UTF-8 is the most compact Unicode representation, we save
some memory as well.
Use toUtf8() to get raw bytes consisting this string, or if necessary use
uCharIterator() to read each character one-by-one.
getLength() returns the length of string in characters rather than bytes. To
get the number of bytes use getUtf8Length(). substring() methods also
work based on character (codepoint) location, as one would naturally expect.