Skip to content

crispy-strawberry/string.zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An allocated string type

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

Using with package manager

  1. Create build.zig.zon in the project root if you don't already have one.
  2. Add the barebones skeleton. (this if you don't know what it looks like)
  3. Inside the dependencies section add -
.string = .{
  .url = "git+https://github.com/crispy-strawberry/string.zig#main",
}
  1. Run zig build and wait for zig to complain about the hash
  2. Copy the provided hash and add it besides the url like -
.string = .{
  .url = "<repo url>",
  .hash = "<the provided hash>"
}
  1. 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"));
  1. Now, in your source files, you can use String by-
const String = @import("string").String;
  1. Enjoy :)

Examples

const hello_world = try String.fromStr(allocator, "Hello World!");

std.debug.print("{}\n", .{hello_world.isAscii()});

Packages

No packages published

Languages