@@ -38,85 +38,24 @@ pub fn mul(comptime T: type, m: T, arg: T) T {
3838 return arg * m ;
3939}
4040
41- pub fn wrapNoOpts (comptime outer : []const u8 , comptime inner : []const u8 ) []const u8 {
42- return "<" ++ outer ++ ">" ++ inner ++ "</" ++ outer ++ "> " ;
41+ pub fn wrapNoOpts (comptime _ : @TypeOf ( []const u8 ), alloc : std . mem . Allocator , outer : [] const u8 , inner : []const u8 ) []const u8 {
42+ return std . fmt . allocPrint ( alloc , "<{s}>{s}</{s}>" , .{ outer , inner , outer }) catch return " " ;
4343}
4444
45- pub fn wrap (comptime outer : []const u8 , comptime options : []const u8 , comptime inner : []const u8 ) []const u8 {
46- return "<" ++ outer ++ " " ++ options ++ ">" ++ inner ++ "</" ++ outer ++ "> " ;
45+ pub fn wrap (comptime _ : @TypeOf ( []const u8 ), alloc : std . mem . Allocator , outer : []const u8 , options : [] const u8 , inner : []const u8 ) []const u8 {
46+ return std . fmt . allocPrint ( alloc , "<{s} {s}>{s}</{s}>" , .{ outer , options , inner , outer }) catch return " " ;
4747}
4848
4949
5050pub fn main () ! void {
51+ // const inner = "<circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"green\" stroke-width=\"4\" fill=\"yellow\" />";
52+ // _ = inner;
5153
52- const inner = "<circle cx=\" 50\" cy=\" 50\" r=\" 40\" stroke=\" green\" stroke-width=\" 4\" fill=\" yellow\" />" ;
53- _ = inner ;
54-
55- const svg = f .partial2Typed ([]const u8 , wrap , "svg" , "viewBox=\" 0 0 300 100\" xmlns=\" http://www.w3.org/2000/svg\" " );
56- const g = f .partialTyped ([]const u8 , wrapNoOpts , "g" );
57- const t = f .partial2Typed ([]const u8 , wrap , "text" , "fill=\" black\" x=\" 0\" y=\" 0\" " );
58-
59- const output = svg (g (t ("Test" )));
60- std .debug .print ("\n {s}" , .{ output });
61-
62-
63- // const file_path = "out/test.svg";
64- // const file = try fs.cwd().createFile(file_path, .{});
65- // defer file.close();
66- // _ = try file.write(output);
67-
68-
54+ const svg = f .partialGeneric ([]const u8 , wrap , .{ allocator , "sv" , "viewBox=\" 0 0 300 100\" xmlns=\" http://www.w3.org/2000/svg\" " });
55+ const g = f .partialGeneric ([]const u8 , wrapNoOpts , .{ allocator , "g" });
56+ // const t = f.partial2([]const u8, wrap, "text", "fill=\"black\" x=\"0\" y=\"0\"");
6957
70- // const input = [_]f32{9, 18, 27};
71- // _ = input;
72- // const result = try map([]f32, @as(f32, 10.0), f.partial(f32, mul, 9));
73- // for (result) |r| {
74- // std.debug.print("\n{d}", .{ r });
75- // }
76-
77- // const file_path = "data/dailyActivity_merged.csv";
78- // const file = try fs.cwd().openFile(file_path, .{ .mode = .read_only });
79- // defer file.close();
80- // const reader = file.reader();
81- // var contents = std.ArrayList(u8).init(allocator);
82- // try reader.streamUntilDelimiter(contents.writer(), '\n', null);
83- // std.debug.print("\n{s}\nCount: {d}", .{ contents.items, contents.items.len });
84-
85- // const line : []const u8 = try allocator.dupe(u8, contents.items);
86-
87- // var splitIt = std.mem.tokenize(u8, line, ",");
88- // while (splitIt.next()) |entry| {
89- // std.debug.print("\n{s}", .{ entry });
90- // }
91-
92- // const cols = [_][]const u8 { "TotalSteps", "TotalDistance" };
93- // comptime var fields: [cols.len]std.builtin.Type.StructField = undefined;
94- // comptime var i: usize = 0;
95- // inline for (cols) |col| {
96- // std.debug.print("\n\n{s}", .{ col });
97- // fields[i] = .{
98- // .name = col,
99- // .type = u8,
100- // .default_value = "",
101- // .is_comptime = false,
102- // .alignment = @alignOf(u8),
103- // };
104- // i += 1;
105- // }
106-
107- // std.debug.print("\n{d}", .{ fields.len });
108- // inline for (fields) |field| {
109- // std.debug.print("\n{s}, {any}", .{ field.name, field.type });
110- // }
111- // const decls: [0]std.builtin.Type.Declaration = [_]std.builtin.Type.Declaration{};
112- // const TestType = @Type(.{
113- // .Struct = .{
114- // .layout = .Auto,
115- // .is_tuple = false,
116- // .fields = &fields,
117- // .decls = &decls,
118- // },
119- // });
120- // const inst: TestType = TestType{ .TotalSteps = 3 };
121- // std.debug.print("\n\n{any}\n{any}", .{ TestType, inst });
58+ const output1 = svg (g ("Test" ));
59+ // const output = svg(output1);
60+ std .debug .print ("\n {s}\n {s}" , .{ output1 , "" });
12261}
0 commit comments