Skip to content

hwu1001/zig-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

A String struct made for Zig.

Inspired by this repo: https://github.com/clownpriest/strings/

To test:

$ cd zig-string/
$ zig test string.zig

Basic Usage:

const std = @import("std");
const String = @import("/some/path/string.zig").String;

pub fn main() !void {
    var buf: [1024]u8 = undefined;
    var fba = std.heap.ThreadSafeFixedBufferAllocator.init(buf[0..]);
    var s = try String.init(&fba.allocator, "hello, world");
    defer s.deinit();
    var matches = try s.findSubstringIndices(&fba.allocator, "hello");
    defer fba.allocator.free(matches);
    // Should print:
    // 0
    // hello, world
    for (matches) |val| {
        std.debug.warn("{}\n", val);
    }
    std.debug.warn("{}\n", s.toSliceConst());
}

Releases

No releases published

Packages

No packages published

Languages