Stylus Studio XML Editor

Table of contents

Appendices

E.2 Methods

Methods

Extensions to a language's native String class or interface

Returns the UTF-16 offset that corresponds to a UTF-32 offset. Used for random access.

NOTE: 

You can always round-trip from a UTF-32 offset to a UTF-16 offset and back. You can round-trip from a UTF-16 offset to a UTF-32 offset and back if and only if the offset16 is not in the middle of a surrogate pair. Unmatched surrogates count as a single UTF-16 value.

UTF-32 offset.

UTF-16 offset

if offset32 is out of bounds.

Returns the UTF-32 offset corresponding to a UTF-16 offset. Used for random access. To find the UTF-32 length of a string, use:

len32 = findOffset32(source, source.length());

NOTE: 

If the UTF-16 offset is into the middle of a surrogate pair, then the UTF-32 offset of the end of the pair is returned; that is, the index of the char after the end of the pair. You can always round-trip from a UTF-32 offset to a UTF-16 offset and back. You can round-trip from a UTF-16 offset to a UTF-32 offset and back if and only if the offset16 is not in the middle of a surrogate pair. Unmatched surrogates count as a single UTF-16 value.

UTF-16 offset

UTF-32 offset

if offset16 is out of bounds.