Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions platform/OsStr.roc
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,24 @@ utf8_to_utf16 = |remaining, out|
[byte, .. as rest] if byte < 0x80 =>
utf8_to_utf16(rest, out.append(U8.to_u16(byte)))
[byte1, byte2, .. as rest] if byte1 < 0xE0 => {
top = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte1, 0x1F)), 6)
top = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte1, 0x1F)), 6)
bottom = U8.to_u32(U8.bitwise_and(byte2, 0x3F))
utf8_to_utf16(rest, out.append(U32.to_u16_wrap(U32.bitwise_or(top, bottom))))
}
[byte1, byte2, byte3, .. as rest] if byte1 < 0xF0 => {
top = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte1, 0x0F)), 12)
middle = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 6)
top = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte1, 0x0F)), 12)
middle = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 6)
bottom = U8.to_u32(U8.bitwise_and(byte3, 0x3F))
code_point = U32.bitwise_or(U32.bitwise_or(top, middle), bottom)
utf8_to_utf16(rest, out.append(U32.to_u16_wrap(code_point)))
}
[byte1, byte2, byte3, byte4, .. as rest] => {
top = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte1, 0x07)), 18)
middle1 = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 12)
middle2 = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte3, 0x3F)), 6)
top = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte1, 0x07)), 18)
middle1 = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 12)
middle2 = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte3, 0x3F)), 6)
bottom = U8.to_u32(U8.bitwise_and(byte4, 0x3F))
code_point = U32.bitwise_or(U32.bitwise_or(U32.bitwise_or(top, middle1), middle2), bottom)
high = U32.to_u16_wrap(0xD800 + U32.shift_right_by(code_point - 0x10000, 10))
high = U32.to_u16_wrap(0xD800 + U32.shr_wrap(code_point - 0x10000, 10))
low = U32.to_u16_wrap(0xDC00 + U32.bitwise_and(code_point - 0x10000, 0x3FF))
utf8_to_utf16(rest, out.append(high).append(low))
}
Expand All @@ -171,7 +171,7 @@ utf16_to_utf8 = |remaining, out, index|
match remaining {
[] => Ok(out)
[high, low, .. as rest] if is_high_surrogate(high) and is_low_surrogate(low) => {
high_bits = U32.shift_left_by(U16.to_u32(high) - 0xD800, 10)
high_bits = U32.shl_wrap(U16.to_u32(high) - 0xD800, 10)
low_bits = U16.to_u32(low) - 0xDC00
code_point = 0x10000 + high_bits + low_bits
utf16_to_utf8(rest, append_code_point_utf8(out, code_point), index + 2)
Expand All @@ -189,7 +189,7 @@ utf16_to_utf8_lossy_help = |remaining, out|
match remaining {
[] => out
[high, low, .. as rest] if is_high_surrogate(high) and is_low_surrogate(low) => {
high_bits = U32.shift_left_by(U16.to_u32(high) - 0xD800, 10)
high_bits = U32.shl_wrap(U16.to_u32(high) - 0xD800, 10)
low_bits = U16.to_u32(low) - 0xDC00
code_point = 0x10000 + high_bits + low_bits
utf16_to_utf8_lossy_help(rest, append_code_point_utf8(out, code_point))
Expand All @@ -205,16 +205,16 @@ append_code_point_utf8 = |out, code_point|
if code_point < 0x80 {
out.append(U32.to_u8_wrap(code_point))
} else if code_point < 0x800 {
out.append(U32.to_u8_wrap(0xC0 + U32.shift_right_by(code_point, 6)))
out.append(U32.to_u8_wrap(0xC0 + U32.shr_wrap(code_point, 6)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(code_point, 0x3F)))
} else if code_point < 0x10000 {
out.append(U32.to_u8_wrap(0xE0 + U32.shift_right_by(code_point, 12)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shift_right_by(code_point, 6), 0x3F)))
out.append(U32.to_u8_wrap(0xE0 + U32.shr_wrap(code_point, 12)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shr_wrap(code_point, 6), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(code_point, 0x3F)))
} else {
out.append(U32.to_u8_wrap(0xF0 + U32.shift_right_by(code_point, 18)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shift_right_by(code_point, 12), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shift_right_by(code_point, 6), 0x3F)))
out.append(U32.to_u8_wrap(0xF0 + U32.shr_wrap(code_point, 18)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shr_wrap(code_point, 12), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shr_wrap(code_point, 6), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(code_point, 0x3F)))
}

Expand Down
30 changes: 15 additions & 15 deletions platform/Path.roc
Original file line number Diff line number Diff line change
Expand Up @@ -379,31 +379,31 @@ utf8_to_utf16 = |remaining, out|
utf8_to_utf16(rest, out.append(U8.to_u16(byte)))

[byte1, byte2, .. as rest] if byte1 < 0xE0 => {
top = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte1, 0x1F)), 6)
top = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte1, 0x1F)), 6)
bottom = U8.to_u32(U8.bitwise_and(byte2, 0x3F))
code_point = U32.bitwise_or(top, bottom)

utf8_to_utf16(rest, out.append(U32.to_u16_wrap(code_point)))
}

[byte1, byte2, byte3, .. as rest] if byte1 < 0xF0 => {
top = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte1, 0x0F)), 12)
middle = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 6)
top = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte1, 0x0F)), 12)
middle = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 6)
bottom = U8.to_u32(U8.bitwise_and(byte3, 0x3F))
code_point = U32.bitwise_or(U32.bitwise_or(top, middle), bottom)

utf8_to_utf16(rest, out.append(U32.to_u16_wrap(code_point)))
}

[byte1, byte2, byte3, byte4, .. as rest] => {
top = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte1, 0x07)), 18)
middle1 = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 12)
middle2 = U32.shift_left_by(U8.to_u32(U8.bitwise_and(byte3, 0x3F)), 6)
top = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte1, 0x07)), 18)
middle1 = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte2, 0x3F)), 12)
middle2 = U32.shl_wrap(U8.to_u32(U8.bitwise_and(byte3, 0x3F)), 6)
bottom = U8.to_u32(U8.bitwise_and(byte4, 0x3F))
upper = U32.bitwise_or(U32.bitwise_or(top, middle1), middle2)
code_point = U32.bitwise_or(upper, bottom)

high = U32.to_u16_wrap(0xD800 + U32.shift_right_by(code_point - 0x10000, 10))
high = U32.to_u16_wrap(0xD800 + U32.shr_wrap(code_point - 0x10000, 10))
low = U32.to_u16_wrap(0xDC00 + U32.bitwise_and(code_point - 0x10000, 0x3FF))

utf8_to_utf16(rest, out.append(high).append(low))
Expand Down Expand Up @@ -432,7 +432,7 @@ utf16_to_utf8 = |remaining, out, index|
[] => Ok(out)

[high, low, .. as rest] if is_high_surrogate(high) and is_low_surrogate(low) => {
high_bits = U32.shift_left_by(U16.to_u32(high) - 0xD800, 10)
high_bits = U32.shl_wrap(U16.to_u32(high) - 0xD800, 10)
low_bits = U16.to_u32(low) - 0xDC00
code_point = 0x10000 + high_bits + low_bits

Expand All @@ -454,7 +454,7 @@ utf16_to_utf8_lossy_help = |remaining, out|
[] => out

[high, low, .. as rest] if is_high_surrogate(high) and is_low_surrogate(low) => {
high_bits = U32.shift_left_by(U16.to_u32(high) - 0xD800, 10)
high_bits = U32.shl_wrap(U16.to_u32(high) - 0xD800, 10)
low_bits = U16.to_u32(low) - 0xDC00
code_point = 0x10000 + high_bits + low_bits

Expand All @@ -473,16 +473,16 @@ append_code_point_utf8 = |out, code_point|
if code_point < 0x80 {
out.append(U32.to_u8_wrap(code_point))
} else if code_point < 0x800 {
out.append(U32.to_u8_wrap(0xC0 + U32.shift_right_by(code_point, 6)))
out.append(U32.to_u8_wrap(0xC0 + U32.shr_wrap(code_point, 6)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(code_point, 0x3F)))
} else if code_point < 0x10000 {
out.append(U32.to_u8_wrap(0xE0 + U32.shift_right_by(code_point, 12)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shift_right_by(code_point, 6), 0x3F)))
out.append(U32.to_u8_wrap(0xE0 + U32.shr_wrap(code_point, 12)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shr_wrap(code_point, 6), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(code_point, 0x3F)))
} else {
out.append(U32.to_u8_wrap(0xF0 + U32.shift_right_by(code_point, 18)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shift_right_by(code_point, 12), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shift_right_by(code_point, 6), 0x3F)))
out.append(U32.to_u8_wrap(0xF0 + U32.shr_wrap(code_point, 18)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shr_wrap(code_point, 12), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(U32.shr_wrap(code_point, 6), 0x3F)))
.append(U32.to_u8_wrap(0x80 + U32.bitwise_and(code_point, 0x3F)))
}

Expand Down
Loading