For the life of me I've tried so many variations, I just can't manage to concatenate the slices during comptime. With this particular example I'm getting the error error: expected type '[]comptime-regex.PathElement', found '*const [1]comptime-regex.PathElement'. I would like to keep using ++ if possible just because I want to understand how to use it.
const std = @import("std");
const PathElementType = enum { element, attribute };
const PathElement = struct { type: PathElementType, value: []const u8 };
fn tokenizeUserPath(comptime userpath: []const u8) []PathElement {
comptime var all_elements: []PathElement = &.{};
comptime var tokenizer = std.mem.tokenizeAny(u8, userpath, "/#");
comptime var idx: comptime_int = 0;
comptime {
while (tokenizer.next()) |content| {
const new_token: [1]PathElement = [1]PathElement{PathElement{ .type = PathElementType.element, .value = content }};
all_elements = all_elements ++ new_token[0..1];
idx += 1;
}
}
return all_elements;
}
test {
const pathTokens: []PathElement = tokenizeUserPath("/categories/messages/unique#5");
_ = pathTokens;
}