Skip to content

Commit

Permalink
update to Zig 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Aug 17, 2023
1 parent 5cff47a commit 30e84a8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
9 changes: 5 additions & 4 deletions src/inlines.zig
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,14 @@ pub const Subject = struct {
brackets_len -= 1;

if (kind == .Link) {
var i = @intCast(i32, brackets_len) - 1;
var i: i32 = @intCast(brackets_len);
i -= 1;
while (i >= 0) : (i -= 1) {
if (self.brackets.items[@intCast(usize, i)].kind == .Link) {
if (!self.brackets.items[@intCast(usize, i)].active) {
if (self.brackets.items[@intCast(i)].kind == .Link) {
if (!self.brackets.items[@intCast(i)].active) {
break;
} else {
self.brackets.items[@intCast(usize, i)].active = false;
self.brackets.items[@intCast(i)].active = false;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub const Parser = struct {
else => try scanners.htmlBlockStart7(line[self.first_nonspace..], &matched),
})) {
const nhb = nodes.NodeHtmlBlock{
.block_type = @truncate(u8, matched),
.block_type = @truncate(matched),
.literal = std.ArrayList(u8).init(self.allocator),
};
container = try self.addChild(container, .{ .HtmlBlock = nhb });
Expand Down Expand Up @@ -800,7 +800,7 @@ pub const Parser = struct {
const chars_to_tab = TAB_STOP - (self.column % TAB_STOP);
if (columns) {
self.partially_consumed_tab = chars_to_tab > count;
const chars_to_advance = std.math.min(count, chars_to_tab);
const chars_to_advance = @min(count, chars_to_tab);
self.column += chars_to_advance;
self.offset += @as(u8, if (self.partially_consumed_tab) 0 else 1);
count -= chars_to_advance;
Expand Down
16 changes: 8 additions & 8 deletions src/strings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ pub fn unescapeInto(text: []const u8, out: *std.ArrayList(u8)) !?usize {
i = 1;
while (i < text.len and ascii.isDigit(text[i])) {
codepoint = (codepoint * 10) + (@as(u32, text[i]) - '0');
codepoint = std.math.min(codepoint, 0x11_0000);
codepoint = @min(codepoint, 0x11_0000);
i += 1;
}
break :block i - 1;
} else if (text[1] == 'x' or text[1] == 'X') {
i = 2;
while (i < text.len and ascii.isHex(text[i])) {
codepoint = (codepoint * 16) + (@as(u32, text[i]) | 32) % 39 - 9;
codepoint = std.math.min(codepoint, 0x11_0000);
codepoint = @min(codepoint, 0x11_0000);
i += 1;
}
break :block i - 2;
Expand All @@ -275,12 +275,12 @@ pub fn unescapeInto(text: []const u8, out: *std.ArrayList(u8)) !?usize {
};

if (num_digits >= 1 and num_digits <= 8 and i < text.len and text[i] == ';') {
try encodeUtf8Into(@truncate(u21, codepoint), out);
try encodeUtf8Into(@truncate(codepoint), out);
return i + 1;
}
}

const size = std.math.min(text.len, ENTITY_MAX_LENGTH);
const size = @min(text.len, ENTITY_MAX_LENGTH);
var i = ENTITY_MIN_LENGTH;
while (i < size) : (i += 1) {
if (text[i] == ' ')
Expand Down Expand Up @@ -437,7 +437,7 @@ pub fn normalizeLabel(allocator: mem.Allocator, s: []const u8) ![]u8 {
var view = std.unicode.Utf8View.initUnchecked(trimmed);
var it = view.iterator();
while (it.nextCodepoint()) |cp| {
var rune = @intCast(i32, cp);
var rune: i32 = @intCast(cp);
if (zunicode.isSpace(rune)) {
if (!last_was_whitespace) {
last_was_whitespace = true;
Expand All @@ -446,7 +446,7 @@ pub fn normalizeLabel(allocator: mem.Allocator, s: []const u8) ![]u8 {
} else {
last_was_whitespace = false;
var lower = zunicode.toLower(rune);
try encodeUtf8Into(@intCast(u21, lower), &buffer);
try encodeUtf8Into(@intCast(lower), &buffer);
}
}
return buffer.toOwnedSlice();
Expand All @@ -466,9 +466,9 @@ pub fn toLower(allocator: mem.Allocator, s: []const u8) ![]u8 {
var view = try std.unicode.Utf8View.init(s);
var it = view.iterator();
while (it.nextCodepoint()) |cp| {
var rune = @intCast(i32, cp);
var rune: i32 = @intCast(cp);
var lower = zunicode.toLower(rune);
try encodeUtf8Into(@intCast(u21, lower), &buffer);
try encodeUtf8Into(@intCast(lower), &buffer);
}
return buffer.toOwnedSlice();
}
Expand Down
2 changes: 1 addition & 1 deletion src/table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn tryOpeningRow(parser: *Parser, container: *nodes.AstNode, aligns: []nodes.Tab
const new_row = try parser.addChild(container, .{ .TableRow = .Body });

var i: usize = 0;
while (i < std.math.min(aligns.len, this_row.len)) : (i += 1) {
while (i < @min(aligns.len, this_row.len)) : (i += 1) {
var cell = try parser.addChild(new_row, .TableCell);
try cell.data.content.appendSlice(this_row[i]);
}
Expand Down

0 comments on commit 30e84a8

Please sign in to comment.