| author | |
| committer | |
| log | 1c874a871fe4795f71edf6e9739b72d071eb453a |
| tree | 3d829ce8be5e9e1bf48faeccdbc2d8f5d138f54b |
| parent | e65d8f82c5f98b20236f571fe4a4e40924ea8dc2 |
3 files changed, 7 insertions(+), 28 deletions(-)
lib/std/buf_map.zig+1-1| ... | ... | @@ -9,7 +9,7 @@ const testing = std.testing; |
| 9 | 9 | pub const BufMap = struct { |
| 10 | 10 | hash_map: BufMapHashMap, |
| 11 | 11 | |
| 12 | pub const BufMapHashMap = StringHashMap([]const u8); | |
| 12 | const BufMapHashMap = StringHashMap([]const u8); | |
| 13 | 13 | |
| 14 | 14 | /// Create a BufMap backed by a specific allocator. |
| 15 | 15 | /// That allocator will be used for both backing allocations |
lib/std/process.zig+6-4| ... | ... | @@ -255,19 +255,21 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap { |
| 255 | 255 | |
| 256 | 256 | while (ptr[i] != 0 and ptr[i] != '=') : (i += 1) {} |
| 257 | 257 | const key_w = ptr[key_start..i]; |
| 258 | const key = try std.unicode.utf16leToUtf8Alloc(allocator, key_w); | |
| 259 | errdefer allocator.free(key); | |
| 258 | 260 | |
| 259 | 261 | if (ptr[i] == '=') i += 1; |
| 260 | 262 | |
| 261 | 263 | const value_start = i; |
| 262 | 264 | while (ptr[i] != 0) : (i += 1) {} |
| 263 | 265 | const value_w = ptr[value_start..i]; |
| 264 | ||
| 265 | try result.storage.putUtf16NoClobber(key_w, value_w); | |
| 266 | const value = try std.unicode.utf16leToUtf8Alloc(allocator, value_w); | |
| 267 | errdefer allocator.free(value); | |
| 266 | 268 | |
| 267 | 269 | i += 1; // skip over null byte |
| 268 | } | |
| 269 | 270 | |
| 270 | try result.storage.reallocUppercaseBuf(); | |
| 271 | try result.putMove(key, value); | |
| 272 | } | |
| 271 | 273 | return result; |
| 272 | 274 | } else if (builtin.os.tag == .wasi and !builtin.link_libc) { |
| 273 | 275 | var environ_count: usize = undefined; |
lib/std/unicode.zig-23| ... | ... | @@ -710,29 +710,6 @@ pub fn utf8ToUtf16Le(utf16le: []u16, utf8: []const u8) !usize { |
| 710 | 710 | return dest_i; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | pub fn utf8ToUtf16LeWriter(writer: anytype, utf8: []const u8) !usize { | |
| 714 | var src_i: usize = 0; | |
| 715 | var bytes_written: usize = 0; | |
| 716 | while (src_i < utf8.len) { | |
| 717 | const n = utf8ByteSequenceLength(utf8[src_i]) catch return error.InvalidUtf8; | |
| 718 | const next_src_i = src_i + n; | |
| 719 | const codepoint = utf8Decode(utf8[src_i..next_src_i]) catch return error.InvalidUtf8; | |
| 720 | if (codepoint < 0x10000) { | |
| 721 | const short = @intCast(u16, codepoint); | |
| 722 | try writer.writeIntLittle(u16, short); | |
| 723 | bytes_written += 2; | |
| 724 | } else { | |
| 725 | const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800; | |
| 726 | const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00; | |
| 727 | try writer.writeIntLittle(u16, high); | |
| 728 | try writer.writeIntLittle(u16, low); | |
| 729 | bytes_written += 4; | |
| 730 | } | |
| 731 | src_i = next_src_i; | |
| 732 | } | |
| 733 | return bytes_written; | |
| 734 | } | |
| 735 | ||
| 736 | 713 | test "utf8ToUtf16Le" { |
| 737 | 714 | var utf16le: [2]u16 = [_]u16{0} ** 2; |
| 738 | 715 | { |