Since not all platforms guarantee that String always uses UTF-8 encoding, you can use this cross-platform API to perform operations on such strings.

Static methods

@:keep@:keepstaticcharCodeAt(s:String, index:Int):Int

Similar to String.charCodeAt but uses the UTF8 character position.

@:keep@:keepstaticcompare(a:String, b:String):Int

Compare two UTF8 strings, character by character.

@:has_untyped@:keep@:keepstaticdecode(s:String):String

Decode an UTF8 string back to an ISO string. Throw an exception if a given UTF8 character is not supported by the decoder.

@:has_untyped@:keep@:keepstaticencode(s:String):String

Encode the input ISO string into the corresponding UTF8 one.

@:keep@:keepstaticiter(s:String, chars:Int ‑> Void):Void

Call the chars function for each UTF8 char of the string.

@:keep@:keepstaticlength(s:String):Int

Returns the number of UTF8 chars of the String.

@:keep@:keepstaticsub(s:String, pos:Int, len:Int):String

This is similar to String.substr but the pos and len parts are considering UTF8 characters.

@:keep@:keepstaticvalidate(s:String):Bool

Tells if the String is correctly encoded as UTF8.

Constructor

@:keep@:keepnew(?size:Int)

Allocate a new Utf8 buffer using an optional bytes size.

Methods

@:keep@:keepaddChar(c:Int):Void

Add the given UTF8 character code to the buffer.

@:has_untyped@:keep@:keeptoString():String

Returns the buffer converted to a String.