diff --git a/lib/std/buf_map.zig b/lib/std/buf_map.zig index 5d155747d2..2a6239c490 100644 --- a/lib/std/buf_map.zig +++ b/lib/std/buf_map.zig @@ -9,7 +9,7 @@ const testing = std.testing; pub const BufMap = struct { hash_map: BufMapHashMap, - pub const BufMapHashMap = StringHashMap([]const u8); + const BufMapHashMap = StringHashMap([]const u8); /// Create a BufMap backed by a specific allocator. /// That allocator will be used for both backing allocations diff --git a/lib/std/process.zig b/lib/std/process.zig index 8892f1cc88..26cde9db51 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -255,19 +255,21 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap { while (ptr[i] != 0 and ptr[i] != '=') : (i += 1) {} const key_w = ptr[key_start..i]; + const key = try std.unicode.utf16leToUtf8Alloc(allocator, key_w); + errdefer allocator.free(key); if (ptr[i] == '=') i += 1; const value_start = i; while (ptr[i] != 0) : (i += 1) {} const value_w = ptr[value_start..i]; - - try result.storage.putUtf16NoClobber(key_w, value_w); + const value = try std.unicode.utf16leToUtf8Alloc(allocator, value_w); + errdefer allocator.free(value); i += 1; // skip over null byte - } - try result.storage.reallocUppercaseBuf(); + try result.putMove(key, value); + } return result; } else if (builtin.os.tag == .wasi and !builtin.link_libc) { var environ_count: usize = undefined; diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 706b12105a..81a7ed838f 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -710,29 +710,6 @@ pub fn utf8ToUtf16Le(utf16le: []u16, utf8: []const u8) !usize { return dest_i; } -pub fn utf8ToUtf16LeWriter(writer: anytype, utf8: []const u8) !usize { - var src_i: usize = 0; - var bytes_written: usize = 0; - while (src_i < utf8.len) { - const n = utf8ByteSequenceLength(utf8[src_i]) catch return error.InvalidUtf8; - const next_src_i = src_i + n; - const codepoint = utf8Decode(utf8[src_i..next_src_i]) catch return error.InvalidUtf8; - if (codepoint < 0x10000) { - const short = @intCast(u16, codepoint); - try writer.writeIntLittle(u16, short); - bytes_written += 2; - } else { - const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800; - const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00; - try writer.writeIntLittle(u16, high); - try writer.writeIntLittle(u16, low); - bytes_written += 4; - } - src_i = next_src_i; - } - return bytes_written; -} - test "utf8ToUtf16Le" { var utf16le: [2]u16 = [_]u16{0} ** 2; {