Open JakubSzark opened 4 years ago
An implementation of format()
to allow for the String to be written to a writer.
I was thinking as simple as this.
pub fn format(
self: *const String,
comptime _: []const u8,
_: std.fmt.FormatOptions,
writer: anytype
) std.os.WriteError!void {
if (self.buffer) | buffer | {
return writer.print("{s}", .{buffer[0..self.size]});
}
}
If need be the format options can be tapped into and the resulting print being formatted according to the options
Could you please update the time complexity column? It doesn't make sense to say f(n)
is at best O(g(n))
, as Big-O notation tells us upper bound already, at best
tells us about lower bound, so the sentence 'f(n)
is at best O(g(n))
' basically says nothing.
Or am I getting wrong the meaning of "best"? Either way best case big-O is confusing.
I guess it will make more sense to list a lower-bound with big-omega, upper-bound with big-o, and amortized time complexity with big-theta.
Just removed that column since its kind of pointless. I doubt myself when I use Big-O all the time haha.
I'd like a string replacement function!
Reference C code: https://stackoverflow.com/questions/779875/what-function-is-to-replace-a-substring-from-a-string-in-c
I have been working with unicode and lexing lately. Maybe it could be in the scope of the library to offer unicode classification and regex matching.
I experimented with Zig's comptime to see if it was possible to generate a minimal automaton for regex recognition, and indeed it is (I love comptime ❤️). I also experimented with binary search to detect if a character belongs to a unicode class (which I parsed from the official database).
If I have time, and if it is of interest, I'll make a repo with a demo for both features.
Maybe make the zig-string.zig
file it's own struct so instead of doing
const String = @import("string").String;
you do const String = @import("string");
if you don't understand me, here is an example of what it looks like make the file the entire struct
Comment below for any features you would like to be added. Please add some example to make it easier to understand :)