Function calcUtf16LeLenImpl [src]

Prototype

pub fn calcUtf16LeLenImpl(utf8: []const u8, comptime surrogates: Surrogates) !usize

Parameters

utf8: []const u8surrogates: Surrogates

Source

pub fn calcUtf16LeLenImpl(utf8: []const u8, comptime surrogates: Surrogates) !usize { const utf8DecodeImpl = switch (surrogates) { .cannot_encode_surrogate_half => utf8Decode, .can_encode_surrogate_half => wtf8Decode, }; var src_i: usize = 0; var dest_len: usize = 0; while (src_i < utf8.len) { const n = try utf8ByteSequenceLength(utf8[src_i]); const next_src_i = src_i + n; const codepoint = try utf8DecodeImpl(utf8[src_i..next_src_i]); if (codepoint < 0x10000) { dest_len += 1; } else { dest_len += 2; } src_i = next_src_i; } return dest_len; }