dom: add comment about buffer with fixed length

The buffer is used for upper case string transformation.
This commit is contained in:
Pierre Tachoire
2023-10-26 09:00:11 +02:00
parent 09d032f6f8
commit 1fe49adba2

View File

@@ -27,6 +27,11 @@ pub const HTMLCollection = struct {
var node: ?*parser.Node = self.root; var node: ?*parser.Node = self.root;
var ntype: parser.NodeType = undefined; var ntype: parser.NodeType = undefined;
// FIXME using a fixed length buffer here avoid the need of an allocator
// to get an upper case match value. But if the match value (a tag
// name) is greater than 128 chars, the code will panic.
// ascii.upperString asserts the buffer size is greater or equals than
// the given string.
var buffer: [128]u8 = undefined; var buffer: [128]u8 = undefined;
const imatch = std.ascii.upperString(&buffer, self.match); const imatch = std.ascii.upperString(&buffer, self.match);
@@ -79,6 +84,11 @@ pub const HTMLCollection = struct {
var is_wildcard = std.mem.eql(u8, self.match, "*"); var is_wildcard = std.mem.eql(u8, self.match, "*");
// FIXME using a fixed length buffer here avoid the need of an allocator
// to get an upper case match value. But if the match value (a tag
// name) is greater than 128 chars, the code will panic.
// ascii.upperString asserts the buffer size is greater or equals than
// the given string.
var buffer: [128]u8 = undefined; var buffer: [128]u8 = undefined;
const imatch = std.ascii.upperString(&buffer, self.match); const imatch = std.ascii.upperString(&buffer, self.match);
@@ -137,6 +147,11 @@ pub const HTMLCollection = struct {
var is_wildcard = std.mem.eql(u8, self.match, "*"); var is_wildcard = std.mem.eql(u8, self.match, "*");
// FIXME using a fixed length buffer here avoid the need of an allocator
// to get an upper case match value. But if the match value (a tag
// name) is greater than 128 chars, the code will panic.
// ascii.upperString asserts the buffer size is greater or equals than
// the given string.
var buffer: [128]u8 = undefined; var buffer: [128]u8 = undefined;
const imatch = std.ascii.upperString(&buffer, self.match); const imatch = std.ascii.upperString(&buffer, self.match);