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
)caseconverter.toScreamingKebab
)caseconverter.toSnake
)caseconverter.toTitle
)The simplest way to use this library is to just call the caseconverter.to<desired-case>
function.
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 });
}
The result must be freed using passed allocator
.