reverse some of the now unneeded changes from squeek

This commit is contained in:
Jonathan Marler 2022-02-04 23:35:22 -07:00
parent e65d8f82c5
commit 1c874a871f
3 changed files with 7 additions and 28 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
{