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 @@
88//! https://handlebarsjs.com/
99
1010const std = @import("std");
11const string = []const u8;
1112const range = @import("range").range;
1213const htmlentities = @import("htmlentities");
1314const root = @import("root");
......@@ -15,7 +16,7 @@ const root = @import("root");
1516const tokenize = @import("./tokenize.zig");
1617const astgen = @import("./astgen.zig");
1718
18pub fn parse(comptime input: []const u8) astgen.Value {
19pub fn parse(comptime input: string) astgen.Value {
1920 return astgen.Value{ .element = astgen.do(tokenize.do(input, &.{ '[', '=', ']', '(', ')', '{', '}', '#', '/', '.', '<', '>' })) };
2021}
2122
......@@ -180,7 +181,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va
180181 }
181182}
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) {
184185 if (args.len == 0) return ctx;
185186 if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\"");
186187 const f = @field(ctx, args[0]);
......@@ -188,12 +189,12 @@ fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(c
188189 return search(args[1..], f);
189190}
190191
191fn FieldSearch(comptime T: type, comptime args: []const []const u8) type {
192 if (args.len > 0 and args[0][0] == '"') return []const u8;
192fn FieldSearch(comptime T: type, comptime args: []const string) type {
193 if (args.len > 0 and args[0][0] == '"') return string;
193194 return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]);
194195}
195196
196fn Field(comptime T: type, comptime field_name: []const u8) type {
197fn Field(comptime T: type, comptime field_name: string) type {
197198 if (std.meta.trait.isIndexable(T) and std.mem.eql(u8, field_name, "len")) {
198199 return usize;
199200 }
......@@ -203,7 +204,7 @@ fn Field(comptime T: type, comptime field_name: []const u8) type {
203204 @compileError(std.fmt.comptimePrint("pek: unknown field {s} on type {s}", .{ field_name, @typeName(T) }));
204205}
205206
206fn entityLookupBefore(in: []const u8) ?htmlentities.Entity {
207fn entityLookupBefore(in: string) ?htmlentities.Entity {
207208 for (htmlentities.ENTITIES) |e| {
208209 if (!std.mem.endsWith(u8, e.entity, ";")) {
209210 continue;
......@@ -249,7 +250,7 @@ const HtmlVoidElements = enum {
249250 wbr,
250251};
251252
252fn contains(haystack: []const []const u8, needle: []const u8) bool {
253fn contains(haystack: []const string, needle: string) bool {
253254 for (haystack) |v| {
254255 if (std.mem.eql(u8, v, needle)) {
255256 return true;