authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-11 02:02:16 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-11 02:02:16 -08:00
logbbac5cad9776dec9ea2e7d110cfcd0e7381a962c
treed0b417cfde1ccc8bdeeac8e376af845b95a8cd4b
parent206d51eb3e028e2f09010875727a39db81009582

lib- alias '[]const u8' to 'string'


1 files changed, 8 insertions(+), 7 deletions(-)

src/lib.zig+8-7
...@@ -8,6 +8,7 @@...@@ -8,6 +8,7 @@
8//! https://handlebarsjs.com/8//! https://handlebarsjs.com/
99
10const std = @import("std");10const std = @import("std");
11const string = []const u8;
11const range = @import("range").range;12const range = @import("range").range;
12const htmlentities = @import("htmlentities");13const htmlentities = @import("htmlentities");
13const root = @import("root");14const root = @import("root");
...@@ -15,7 +16,7 @@ const root = @import("root");...@@ -15,7 +16,7 @@ const root = @import("root");
15const tokenize = @import("./tokenize.zig");16const tokenize = @import("./tokenize.zig");
16const astgen = @import("./astgen.zig");17const astgen = @import("./astgen.zig");
1718
18pub fn parse(comptime input: []const u8) astgen.Value {19pub fn parse(comptime input: string) astgen.Value {
19 return astgen.Value{ .element = astgen.do(tokenize.do(input, &.{ '[', '=', ']', '(', ')', '{', '}', '#', '/', '.', '<', '>' })) };20 return astgen.Value{ .element = astgen.do(tokenize.do(input, &.{ '[', '=', ']', '(', ')', '{', '}', '#', '/', '.', '<', '>' })) };
20}21}
2122
...@@ -180,7 +181,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va...@@ -180,7 +181,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va
180 }181 }
181}182}
182183
183fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(ctx), args) {184fn search(comptime args: []const string, ctx: anytype) FieldSearch(@TypeOf(ctx), args) {
184 if (args.len == 0) return ctx;185 if (args.len == 0) return ctx;
185 if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\"");186 if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\"");
186 const f = @field(ctx, args[0]);187 const f = @field(ctx, args[0]);
...@@ -188,12 +189,12 @@ fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(c...@@ -188,12 +189,12 @@ fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(c
188 return search(args[1..], f);189 return search(args[1..], f);
189}190}
190191
191fn FieldSearch(comptime T: type, comptime args: []const []const u8) type {192fn FieldSearch(comptime T: type, comptime args: []const string) type {
192 if (args.len > 0 and args[0][0] == '"') return []const u8;193 if (args.len > 0 and args[0][0] == '"') return string;
193 return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]);194 return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]);
194}195}
195196
196fn Field(comptime T: type, comptime field_name: []const u8) type {197fn Field(comptime T: type, comptime field_name: string) type {
197 if (std.meta.trait.isIndexable(T) and std.mem.eql(u8, field_name, "len")) {198 if (std.meta.trait.isIndexable(T) and std.mem.eql(u8, field_name, "len")) {
198 return usize;199 return usize;
199 }200 }
...@@ -203,7 +204,7 @@ fn Field(comptime T: type, comptime field_name: []const u8) type {...@@ -203,7 +204,7 @@ fn Field(comptime T: type, comptime field_name: []const u8) type {
203 @compileError(std.fmt.comptimePrint("pek: unknown field {s} on type {s}", .{ field_name, @typeName(T) }));204 @compileError(std.fmt.comptimePrint("pek: unknown field {s} on type {s}", .{ field_name, @typeName(T) }));
204}205}
205206
206fn entityLookupBefore(in: []const u8) ?htmlentities.Entity {207fn entityLookupBefore(in: string) ?htmlentities.Entity {
207 for (htmlentities.ENTITIES) |e| {208 for (htmlentities.ENTITIES) |e| {
208 if (!std.mem.endsWith(u8, e.entity, ";")) {209 if (!std.mem.endsWith(u8, e.entity, ";")) {
209 continue;210 continue;
...@@ -249,7 +250,7 @@ const HtmlVoidElements = enum {...@@ -249,7 +250,7 @@ const HtmlVoidElements = enum {
249 wbr,250 wbr,
250};251};
251252
252fn contains(haystack: []const []const u8, needle: []const u8) bool {253fn contains(haystack: []const string, needle: string) bool {
253 for (haystack) |v| {254 for (haystack) |v| {
254 if (std.mem.eql(u8, v, needle)) {255 if (std.mem.eql(u8, v, needle)) {
255 return true;256 return true;