Function utf16CodeUnitSequenceLength [src]
Given the first code unit of a UTF-16 codepoint, returns a number 1-2
indicating the total length of the codepoint in UTF-16 code units.
If this code unit does not match the form of a UTF-16 start code unit, returns Utf16InvalidStartCodeUnit.
Prototype
pub fn utf16CodeUnitSequenceLength(first_code_unit: u16) !u2
Parameters
first_code_unit: u16
Example
test utf16CodeUnitSequenceLength {
try testing.expectEqual(@as(u2, 1), try utf16CodeUnitSequenceLength('a'));
try testing.expectEqual(@as(u2, 1), try utf16CodeUnitSequenceLength(0xFFFF));
try testing.expectEqual(@as(u2, 2), try utf16CodeUnitSequenceLength(0xDBFF));
try testing.expectError(error.Utf16InvalidStartCodeUnit, utf16CodeUnitSequenceLength(0xDFFF));
}
Source
pub fn utf16CodeUnitSequenceLength(first_code_unit: u16) !u2 {
if (utf16IsHighSurrogate(first_code_unit)) return 2;
if (utf16IsLowSurrogate(first_code_unit)) return error.Utf16InvalidStartCodeUnit;
return 1;
}