Compare commits

...

2 Commits

Author SHA1 Message Date
Jarred Sumner
bd0645827d Update src/router.zig 2024-06-26 02:47:15 -07:00
Jarred Sumner
fa3469dbc3 Delete some dead code 2024-06-25 20:24:10 -07:00
2 changed files with 1 additions and 158 deletions

View File

@@ -1203,7 +1203,7 @@ const Pattern = struct {
/// `null` means invalid. Error messages are logged.
/// That way, we can provide a list of all invalid routes rather than failing the first time.
pub fn validate(input: string, allocator: std.mem.Allocator, log: *Logger.Log) ?ValidationResult {
if (CodepointIterator.needsUTF8Decoding(input)) {
if (!bun.strings.isAllASCII(input)) {
const source = Logger.Source.initEmptyFile(input);
log.addErrorFmt(
&source,

View File

@@ -4552,85 +4552,6 @@ pub const PackedCodepointIterator = struct {
return true;
}
inline fn nextCodepointSlice(it: *Iterator) []const u8 {
const bytes = it.bytes;
const prev = it.i;
const next_ = prev + it.next_width;
if (bytes.len <= next_) return "";
const cp_len = utf8ByteSequenceLength(bytes[next_]);
it.next_width = cp_len;
it.i = @min(next_, bytes.len);
const slice = bytes[prev..][0..cp_len];
it.width = @as(u3, @intCast(slice.len));
return slice;
}
pub fn needsUTF8Decoding(slice: string) bool {
var it = Iterator{ .bytes = slice, .i = 0 };
while (true) {
const part = it.nextCodepointSlice();
@setRuntimeSafety(false);
switch (part.len) {
0 => return false,
1 => continue,
else => return true,
}
}
}
pub fn scanUntilQuotedValueOrEOF(iter: *Iterator, comptime quote: CodePointType) usize {
while (iter.c > -1) {
if (!switch (iter.nextCodepoint()) {
quote => false,
'\\' => brk: {
if (iter.nextCodepoint() == quote) {
continue;
}
break :brk true;
},
else => true,
}) {
return iter.i + 1;
}
}
return iter.i;
}
pub fn nextCodepoint(it: *Iterator) CodePointType {
const slice = it.nextCodepointSlice();
it.c = switch (slice.len) {
0 => zeroValue,
1 => @as(CodePointType, @intCast(slice[0])),
2 => @as(CodePointType, @intCast(std.unicode.utf8Decode2(slice) catch unreachable)),
3 => @as(CodePointType, @intCast(std.unicode.utf8Decode3(slice) catch unreachable)),
4 => @as(CodePointType, @intCast(std.unicode.utf8Decode4(slice) catch unreachable)),
else => unreachable,
};
return it.c;
}
/// Look ahead at the next n codepoints without advancing the iterator.
/// If fewer than n codepoints are available, then return the remainder of the string.
pub fn peek(it: *Iterator, n: usize) []const u8 {
const original_i = it.i;
defer it.i = original_i;
var end_ix = original_i;
var found: usize = 0;
while (found < n) : (found += 1) {
const next_codepoint = it.nextCodepointSlice() orelse return it.bytes[original_i..];
end_ix += next_codepoint.len;
}
return it.bytes[original_i..end_ix];
}
};
pub fn NewCodePointIterator(comptime CodePointType: type, comptime zeroValue: comptime_int) type {
@@ -4687,84 +4608,6 @@ pub fn NewCodePointIterator(comptime CodePointType: type, comptime zeroValue: co
return true;
}
inline fn nextCodepointSlice(it: *Iterator) []const u8 {
const bytes = it.bytes;
const prev = it.i;
const next_ = prev + it.next_width;
if (bytes.len <= next_) return "";
const cp_len = utf8ByteSequenceLength(bytes[next_]);
it.next_width = cp_len;
it.i = @min(next_, bytes.len);
const slice = bytes[prev..][0..cp_len];
it.width = @as(u3, @intCast(slice.len));
return slice;
}
pub fn needsUTF8Decoding(slice: string) bool {
var it = Iterator{ .bytes = slice, .i = 0 };
while (true) {
const part = it.nextCodepointSlice();
@setRuntimeSafety(false);
switch (part.len) {
0 => return false,
1 => continue,
else => return true,
}
}
}
pub fn scanUntilQuotedValueOrEOF(iter: *Iterator, comptime quote: CodePointType) usize {
while (iter.c > -1) {
if (!switch (iter.nextCodepoint()) {
quote => false,
'\\' => brk: {
if (iter.nextCodepoint() == quote) {
continue;
}
break :brk true;
},
else => true,
}) {
return iter.i + 1;
}
}
return iter.i;
}
pub fn nextCodepoint(it: *Iterator) CodePointType {
const slice = it.nextCodepointSlice();
it.c = switch (slice.len) {
0 => zeroValue,
1 => @as(CodePointType, @intCast(slice[0])),
2 => @as(CodePointType, @intCast(std.unicode.utf8Decode2(slice) catch unreachable)),
3 => @as(CodePointType, @intCast(std.unicode.utf8Decode3(slice) catch unreachable)),
4 => @as(CodePointType, @intCast(std.unicode.utf8Decode4(slice) catch unreachable)),
else => unreachable,
};
return it.c;
}
/// Look ahead at the next n codepoints without advancing the iterator.
/// If fewer than n codepoints are available, then return the remainder of the string.
pub fn peek(it: *Iterator, n: usize) []const u8 {
const original_i = it.i;
defer it.i = original_i;
var end_ix = original_i;
for (0..n) |_| {
const next_codepoint = it.nextCodepointSlice() orelse return it.bytes[original_i..];
end_ix += next_codepoint.len;
}
return it.bytes[original_i..end_ix];
}
};
}