update more of the std lib to use @as

This commit is contained in:
Andrew Kelley
2019-11-07 18:52:09 -05:00
parent a2acc27872
commit aa0daea541
28 changed files with 145 additions and 145 deletions

View File

@@ -7,10 +7,10 @@ const mem = std.mem;
/// Returns how many bytes the UTF-8 representation would require
/// for the given codepoint.
pub fn utf8CodepointSequenceLength(c: u32) !u3 {
if (c < 0x80) return u3(1);
if (c < 0x800) return u3(2);
if (c < 0x10000) return u3(3);
if (c < 0x110000) return u3(4);
if (c < 0x80) return @as(u3, 1);
if (c < 0x800) return @as(u3, 2);
if (c < 0x10000) return @as(u3, 3);
if (c < 0x110000) return @as(u3, 4);
return error.CodepointTooLarge;
}
@@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 {
/// returns a number 1-4 indicating the total length of the codepoint in bytes.
/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.
pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
if (first_byte < 0b10000000) return u3(1);
if (first_byte & 0b11100000 == 0b11000000) return u3(2);
if (first_byte & 0b11110000 == 0b11100000) return u3(3);
if (first_byte & 0b11111000 == 0b11110000) return u3(4);
if (first_byte < 0b10000000) return @as(u3, 1);
if (first_byte & 0b11100000 == 0b11000000) return @as(u3, 2);
if (first_byte & 0b11110000 == 0b11100000) return @as(u3, 3);
if (first_byte & 0b11111000 == 0b11110000) return @as(u3, 4);
return error.Utf8InvalidStartByte;
}