Skip to content

Unicode (utf-8) rework #5559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 7 additions & 6 deletions lib/std/json.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ fn unescapeString(output: []u8, input: []const u8) !void {
inIndex += 6;
} else |err| {
// it might be a surrogate pair
if (err != error.Utf8CannotEncodeSurrogateHalf) {
if (err != error.UnicodeSurrogateHalf) {
return error.InvalidUnicodeHexSymbol;
}
// check if a second code unit is present
Expand Down Expand Up @@ -2532,15 +2532,16 @@ pub fn stringify(
'\r' => try out_stream.writeAll("\\r"),
'\t' => try out_stream.writeAll("\\t"),
else => {
const ulen = std.unicode.utf8ByteSequenceLength(value[i]) catch unreachable;
// control characters (only things left with 1 byte length) should always be printed as unicode escapes
if (ulen == 1 or options.string.String.escape_unicode) {
const codepoint = std.unicode.utf8Decode(value[i .. i + ulen]) catch unreachable;
try outputUnicodeEscape(codepoint, out_stream);
if ((value[i] < 128) or options.string.String.escape_unicode) {
const c = std.unicode.utf8Decode(value[i..]) catch unreachable;
try outputUnicodeEscape(c.codepoint, out_stream);
i += c.utf8len - 1;
} else {
var ulen = std.unicode.utf8ByteSequenceLength(value[i]) catch unreachable;
try out_stream.writeAll(value[i .. i + ulen]);
i += ulen - 1;
}
i += ulen - 1;
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/process.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub const GetEnvVarOwnedError = error{
pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 {
if (builtin.os.tag == .windows) {
const result_w = blk: {
const key_w = try std.unicode.utf8ToUtf16LeWithNull(allocator, key);
const key_w = std.unicode.utf8ToUtf16LeWithNull(allocator, key) catch return error.InvalidUtf8;
defer allocator.free(key_w);

break :blk std.os.getenvW(key_w) orelse return error.EnvironmentVariableNotFound;
Expand Down
Loading