Inspired by Rust's String
type.
Implementation mostly ported from Rust.
Provides helper functions that make working with strings easier.
I try to keep names consistent with std.ArrayList
- Create
build.zig.zon
in the project root if you don't already have one. - Add the barebones skeleton. (this if you don't know what it looks like)
- Inside the dependencies section add -
.string = .{
.url = "git+https://github.com/crispy-strawberry/string.zig#main",
}
- Run
zig build
and wait for zig to complain about the hash - Copy the provided hash and add it besides the url like -
.string = .{
.url = "<repo url>",
.hash = "<the provided hash>"
}
- In your
build.zig
, add -
const string = b.dependency("string", .{ .optimize = optimize, .target = target });
// Replace exe with whatever you are using.
exe.addModule("string", string.module("string"));
- Now, in your source files, you can use
String
by-
const String = @import("string").String;
- Enjoy :)
const hello_world = try String.fromStr(allocator, "Hello World!");
std.debug.print("{}\n", .{hello_world.isAscii()});