Skip to content

Commit

Permalink
Update to 0.11.0-dev.1253+fcee1bf99
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubvf committed Jan 11, 2023
1 parent 71f5155 commit d23a4df
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
24 changes: 12 additions & 12 deletions src/autolink.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ pub const AutolinkProcessor = struct {
assert(remain.len > 0);
org.post.insertAfter(try self.makeInline(.{ .Text = try self.allocator.dupe(u8, remain) }));
}
self.text.* = self.allocator.shrink(self.text.*, i);
self.text.* = try self.allocator.realloc(self.text.*, i);
return;
}
}
}

const WWW_DELIMS = strings.createMap("*_~([");
fn wwwMatch(self: AutolinkProcessor, i: usize) !?Match {
if (i > 0 and !ascii.isSpace(self.text.*[i - 1]) and !WWW_DELIMS[self.text.*[i - 1]]) {
if (i > 0 and !ascii.isWhitespace(self.text.*[i - 1]) and !WWW_DELIMS[self.text.*[i - 1]]) {
return null;
}

Expand All @@ -72,7 +72,7 @@ pub const AutolinkProcessor = struct {
var link_end = (try checkDomain(self.text.*[i..], false)) orelse return null;

while (i + link_end < self.text.len and
!ascii.isSpace(self.text.*[i + link_end])) : (link_end += 1)
!ascii.isWhitespace(self.text.*[i + link_end])) : (link_end += 1)
{}

link_end = autolinkDelim(self.text.*[i..], link_end);
Expand All @@ -83,7 +83,7 @@ pub const AutolinkProcessor = struct {

var inl = try self.makeInline(.{
.Link = .{
.url = url.toOwnedSlice(),
.url = try url.toOwnedSlice(),
.title = &[_]u8{},
},
});
Expand All @@ -107,7 +107,7 @@ pub const AutolinkProcessor = struct {

var rewind: usize = 0;
while (rewind < i and
ascii.isAlpha(self.text.*[i - rewind - 1])) : (rewind += 1)
ascii.isAlphabetic(self.text.*[i - rewind - 1])) : (rewind += 1)
{}

if (!scheme_matched: {
Expand All @@ -123,7 +123,7 @@ pub const AutolinkProcessor = struct {

var link_end = (try checkDomain(self.text.*[i + 3 ..], true)) orelse return null;

while (link_end < size - i and !ascii.isSpace(self.text.*[i + link_end])) : (link_end += 1) {}
while (link_end < size - i and !ascii.isWhitespace(self.text.*[i + link_end])) : (link_end += 1) {}

link_end = autolinkDelim(self.text.*[i..], link_end);

Expand Down Expand Up @@ -151,7 +151,7 @@ pub const AutolinkProcessor = struct {
var ns: usize = 0;
while (rewind < i) {
const c = self.text.*[i - rewind - 1];
if (ascii.isAlNum(c) or EMAIL_OK_SET[c]) {
if (ascii.isAlphanumeric(c) or EMAIL_OK_SET[c]) {
rewind += 1;
continue;
}
Expand All @@ -174,11 +174,11 @@ pub const AutolinkProcessor = struct {
while (link_end < size - i) {
const c = self.text.*[i + link_end];

if (ascii.isAlNum(c)) {
if (ascii.isAlphanumeric(c)) {
// empty
} else if (c == '@') {
nb += 1;
} else if (c == '.' and link_end < size - i - 1 and ascii.isAlNum(self.text.*[i + link_end + 1])) {
} else if (c == '.' and link_end < size - i - 1 and ascii.isAlphanumeric(self.text.*[i + link_end + 1])) {
np += 1;
} else if (c != '-' and c != '_') {
break;
Expand All @@ -187,7 +187,7 @@ pub const AutolinkProcessor = struct {
link_end += 1;
}

if (link_end < 2 or nb != 1 or np == 0 or (!ascii.isAlpha(self.text.*[i + link_end - 1]) and self.text.*[i + link_end - 1] != '.')) {
if (link_end < 2 or nb != 1 or np == 0 or (!ascii.isAlphabetic(self.text.*[i + link_end - 1]) and self.text.*[i + link_end - 1] != '.')) {
return null;
}

Expand All @@ -199,7 +199,7 @@ pub const AutolinkProcessor = struct {

var inl = try self.makeInline(.{
.Link = .{
.url = url.toOwnedSlice(),
.url = try url.toOwnedSlice(),
.title = &[_]u8{},
},
});
Expand Down Expand Up @@ -270,7 +270,7 @@ pub const AutolinkProcessor = struct {
var new_end = link_end - 2;

while (new_end > 0 and
ascii.isAlNum(data[new_end])) : (new_end -= 1)
ascii.isAlphanumeric(data[new_end])) : (new_end -= 1)
{}

if (new_end < link_end - 2 and data[new_end] == '&') {
Expand Down
4 changes: 2 additions & 2 deletions src/html.zig
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn HtmlFormatter(comptime Writer: type) type {
try self.writeAll("<pre><code>");
} else {
var first_tag: usize = 0;
while (first_tag < ncb.info.?.len and !ascii.isSpace(ncb.info.?[first_tag]))
while (first_tag < ncb.info.?.len and !ascii.isWhitespace(ncb.info.?[first_tag]))
first_tag += 1;

try self.writeAll("<pre><code class=\"language-");
Expand Down Expand Up @@ -503,7 +503,7 @@ pub fn HtmlFormatter(comptime Writer: type) type {
for (TAGFILTER_BLACKLIST) |t| {
const j = i + t.len;
if (literal.len > j and std.ascii.eqlIgnoreCase(t, literal[i..j])) {
return ascii.isSpace(literal[j]) or
return ascii.isWhitespace(literal[j]) or
literal[j] == '>' or
(literal[j] == '/' and literal.len >= j + 2 and literal[j + 1] == '>');
}
Expand Down
18 changes: 9 additions & 9 deletions src/inlines.zig
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub const Subject = struct {

fn handleBackslash(self: *Subject) !*nodes.AstNode {
self.pos += 1;
if (ascii.isPunct(self.peekChar() orelse 0)) {
if (strings.isPunct(self.peekChar() orelse 0)) {
self.pos += 1;
var contents = try self.allocator.dupe(u8, self.input[self.pos - 1 .. self.pos]);
return try self.makeInline(.{ .Text = contents });
Expand All @@ -366,11 +366,11 @@ pub const Subject = struct {
var out = std.ArrayList(u8).init(self.allocator);
if (try strings.unescapeInto(self.input[self.pos..], &out)) |len| {
self.pos += len;
return try self.makeInline(.{ .Text = out.toOwnedSlice() });
return try self.makeInline(.{ .Text = try out.toOwnedSlice() });
}

try out.append('&');
return try self.makeInline(.{ .Text = out.toOwnedSlice() });
return try self.makeInline(.{ .Text = try out.toOwnedSlice() });
}

fn handlePointyBrace(self: *Subject) !*nodes.AstNode {
Expand Down Expand Up @@ -447,7 +447,7 @@ pub const Subject = struct {
while (ens_ems[0] > 0) : (ens_ems[0] -= 1)
try text.appendSlice("–");

return try self.makeInline(.{ .Text = text.toOwnedSlice() });
return try self.makeInline(.{ .Text = try text.toOwnedSlice() });
}

fn handlePeriod(self: *Subject) !*nodes.AstNode {
Expand Down Expand Up @@ -561,9 +561,9 @@ pub const Subject = struct {
return null;

var opener_text = opener.inl.data.value.text_mut().?;
opener_text.* = self.allocator.shrink(opener_text.*, opener_num_chars);
opener_text.* = try self.allocator.realloc(opener_text.*, opener_num_chars);
var closer_text = closer.inl.data.value.text_mut().?;
closer_text.* = self.allocator.shrink(closer_text.*, closer_num_chars);
closer_text.* = try self.allocator.realloc(closer_text.*, closer_num_chars);

var delim = closer.prev;
while (delim != null and delim != opener) {
Expand Down Expand Up @@ -709,7 +709,7 @@ pub const Subject = struct {
if (c == '\\') {
self.pos += 1;
length += 1;
if (ascii.isPunct(self.peekChar() orelse 0)) {
if (strings.isPunct(self.peekChar() orelse 0)) {
self.pos += 1;
length += 1;
}
Expand Down Expand Up @@ -809,7 +809,7 @@ pub const Subject = struct {
var nb_p: usize = 0;

while (i < len) {
if (input[i] == '\\' and i + 1 < len and ascii.isPunct(input[i + 1])) {
if (input[i] == '\\' and i + 1 < len and strings.isPunct(input[i + 1])) {
i += 2;
} else if (input[i] == '(') {
nb_p += 1;
Expand All @@ -821,7 +821,7 @@ pub const Subject = struct {
break;
nb_p -= 1;
i += 1;
} else if (ascii.isSpace(input[i])) {
} else if (ascii.isWhitespace(input[i])) {
if (i == 0)
return false;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn main() !void {
var arr = std.ArrayList(u8).init(allocator);
errdefer arr.deinit();
try html.print(arr.writer(), allocator, options, doc);
break :blk arr.toOwnedSlice();
break :blk try arr.toOwnedSlice();
};
defer allocator.free(output);

Expand Down
4 changes: 2 additions & 2 deletions src/parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ pub const Parser = struct {

if (c == '*' or c == '-' or c == '+') {
pos += 1;
if (!ascii.isSpace(line[pos])) {
if (!ascii.isWhitespace(line[pos])) {
return false;
}

Expand Down Expand Up @@ -952,7 +952,7 @@ pub const Parser = struct {

pos += 1;

if (!ascii.isSpace(line[pos])) {
if (!ascii.isWhitespace(line[pos])) {
return false;
}

Expand Down
11 changes: 9 additions & 2 deletions src/strings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ test "removeTrailingBlankLines" {
}
}

pub fn isPunct(char: u8) bool {
return switch (char) {
'!', '\"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~' => true,
else => false,
};
}

fn encodeUtf8Into(in_cp: u21, al: *std.ArrayList(u8)) !void {
// utf8Encode throws:
// - Utf8CannotEncodeSurrogateHalf, which we guard against that by
Expand Down Expand Up @@ -257,7 +264,7 @@ pub fn unescapeInto(text: []const u8, out: *std.ArrayList(u8)) !?usize {
break :block i - 1;
} else if (text[1] == 'x' or text[1] == 'X') {
i = 2;
while (i < text.len and ascii.isXDigit(text[i])) {
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);
i += 1;
Expand Down Expand Up @@ -374,7 +381,7 @@ fn unescape(allocator: mem.Allocator, s: []const u8) ![]u8 {
var r: usize = 0;

while (r < s.len) : (r += 1) {
if (s[r] == '\\' and r + 1 < s.len and ascii.isPunct(s[r + 1]))
if (s[r] == '\\' and r + 1 < s.len and isPunct(s[r + 1]))
r += 1;
try buffer.append(s[r]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn freeNested(allocator: std.mem.Allocator, v: [][]u8) void {
fn row(allocator: std.mem.Allocator, line: []const u8) !?[][]u8 {
const len = line.len;
var v = std.ArrayList([]u8).init(allocator);
errdefer freeNested(allocator, v.toOwnedSlice());
errdefer freeNested(allocator, v.toOwnedSlice() catch unreachable);
var offset: usize = 0;

if (len > 0 and line[0] == '|')
Expand All @@ -33,7 +33,7 @@ fn row(allocator: std.mem.Allocator, line: []const u8) !?[][]u8 {
if (cell_matched > 0 or pipe_matched > 0) {
var cell = try unescapePipes(allocator, line[offset .. offset + cell_matched]);
strings.trimIt(&cell);
try v.append(cell.toOwnedSlice());
try v.append(try cell.toOwnedSlice());
}

offset += cell_matched + pipe_matched;
Expand All @@ -49,10 +49,10 @@ fn row(allocator: std.mem.Allocator, line: []const u8) !?[][]u8 {
}

if (offset != len or v.items.len == 0) {
freeNested(allocator, v.toOwnedSlice());
freeNested(allocator, try v.toOwnedSlice());
return null;
} else {
return v.toOwnedSlice();
return try v.toOwnedSlice();
}
}

Expand Down

0 comments on commit d23a4df

Please sign in to comment.