funbiscuit/zig-caseconverter
A case conversion library for zig
A zig library for transforming strings from one case into another (e.g. camelCase -> kebab-case).
Implementation is inspired by case converter for Python.
caseconverter.toCamel)caseconverter.toCobol)caseconverter.toFlat)caseconverter.toKebab)caseconverter.toMacro)caseconverter.toPascal)caseconverter.toScreamingSnake). Same as toMacro, but coolercaseconverter.toScreamingKebab). Same as toCobol, but coolercaseconverter.toSnake)caseconverter.toTitle)Developers tend to either use
Depending on which developer you are, you need to run different zig fetch commands:
Version of zig-caseconverter that works with a tagged release of Zig. Replace <REPLACE ME> with the version of
zig-caseconverter that you want to use. See: https://github.com/funbiscuit/zig-caseconverter/releases
zig fetch --save https://github.com/funbiscuit/zig-caseconverter/archive/refs/tags/<REPLACE ME>.tar.gz
Version of zig-caseconverter that works with latest build of Zig master branch
zig fetch --save git+https://github.com/funbiscuit/zig-caseconverter
Then add the following to build.zig:
const caseconverter = b.dependency("caseconverter", .{});
exe.root_module.addImport("caseconverter", caseconverter.module("caseconverter"));
The simplest way to use this library is to just call the caseconverter.to<desired-case> function.
Example code is from examples/simple.zig.
const std = @import("std");
const caseconverter = @import("caseconverter");
pub fn main() !void {
var gpa = std.heap.DebugAllocator(.{}){};
defer _ = gpa.deinit();
const input = "hello, world";
const camelCased = try caseconverter.toCamel(gpa.allocator(), "hello, world", .{});
defer gpa.allocator().free(camelCased);
const macroCased = try caseconverter.toMacro(gpa.allocator(), "hello, world", .{});
defer gpa.allocator().free(macroCased);
const camelCased2 = try caseconverter.toCamel(gpa.allocator(), macroCased, .{});
defer gpa.allocator().free(camelCased2);
std.debug.print("`{s}` camelcased is `{s}`\n", .{ input, camelCased });
std.debug.print("`{s}` macrocased is `{s}`\n", .{ input, macroCased });
std.debug.print("`{s}` camelcased is `{s}`\n", .{ macroCased, camelCased2 });
}
Output:
$ zig build examples
$ zig-out/bin/simple
`hello, world` camelcased is `helloWorld`
`hello, world` macrocased is `HELLO_WORLD`
`HELLO_WORLD` camelcased is `helloWorld`
Contributions are welcome in the form of bug reports, feature suggestions, and pull requests.
Before starting substantial work, please open an issue or discussion to discuss the change. This ensures effort is not wasted and the contribution aligns with the project's goals.
Open an issue to report a bug or suggest a new feature. Please include:
main.