Function calcWtf8Len [src]
Returns the length, in bytes, that would be necessary to encode the
given WTF-16 LE slice as WTF-8.
Prototype
pub fn calcWtf8Len(wtf16le: []const u16) usize
Parameters
wtf16le: []const u16
Source
pub fn calcWtf8Len(wtf16le: []const u16) usize {
var it = Wtf16LeIterator.init(wtf16le);
var num_wtf8_bytes: usize = 0;
while (it.nextCodepoint()) |codepoint| {
// Note: If utf8CodepointSequenceLength is ever changed to error on surrogate
// codepoints, then it would no longer be eligible to be used in this context.
num_wtf8_bytes += utf8CodepointSequenceLength(codepoint) catch |err| switch (err) {
error.CodepointTooLarge => unreachable,
};
}
return num_wtf8_bytes;
}