pub fn init(gpa: Allocator, cmd_line_w: []const u16) Windows.InitError!Windows gpa: Allocatorcmd_line_w: []const u16115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 pub fn init(gpa: Allocator, cmd_line_w: []const u16) Windows.InitError!Windows {
const wtf8_len = std.unicode.calcWtf8Len(cmd_line_w);
// This buffer must be large enough to contain contiguous NUL-terminated slices
// of each argument.
// - During parsing, the length of a parsed argument will always be equal to
// to less than its unparsed length
// - The first argument needs one extra byte of space allocated for its NUL
// terminator, but for each subsequent argument the necessary whitespace
// between arguments guarantees room for their NUL terminator(s).
const buffer = try gpa.alloc(u8, wtf8_len + 1);
errdefer gpa.free(buffer);
return .{
.allocator = gpa,
.cmd_line = cmd_line_w,
.buffer = buffer,
};
}
cmd_line_wmust be a WTF16-LE-encoded string.The iterator stores and uses
cmd_line_w, so its memory must be valid for at least as long as the returned Windows.