UnicodeHelpers

Helpers for implementing methods in StringRange and UnicodeType. They are provided publicly in case they can be useful for building other custom string-based types.

Methods

(static) compareLength(a, b) → {number}

Compare the length of two strings, using the count of unicode codepoints

Parameters:
NameTypeDescription
astring

reference string

bstring

string to compare with

Returns:

negative if a has less; 0 if equal; positive if a has more

Type: 
number

(static) lastCodepoint(str) → {number}

Get the last codepoint of a string

Parameters:
NameTypeDescription
strstring

non-empty string to fetch the codepoint of

Returns:

the codepoint

Type: 
number

(static) length(str) → {number}

Count number of unicode codepoints in a string, e.g. the UTF-32 encoded string length

Parameters:
NameTypeDescription
strstring

the string to get the length of

Returns:

the string length

Type: 
number

(generator, static) pairwiseIterate(a, b) → {Array.<number>}

Pairwise iteration of the codepoints of two equal length strings

Parameters:
NameTypeDescription
astring

first string

bstring

second string

Yields:

tuple of codepoints [a, b]

Type: 
Array.<number>

(static) utf16Length(codepoint) → {number}

Get the UTF-16 string length for a given codepoint

Parameters:
NameTypeDescription
codepointnumber

the unicode codepoint

Returns:

two if its a surrogate pair, else one

Type: 
number