Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/zig-out/
**/zig-cache/

.zig-cache/*
21 changes: 7 additions & 14 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

_ = b.addModule("deunicode", .{
.source_file = .{ .path = "src/lib.zig" },
.dependencies = &.{},
});

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.name = "deunicode",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
.root_module = b.addModule("deunicode", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
}),
});

// This declares intent for the library to be installed into the standard
Expand All @@ -37,9 +32,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
.root_module = lib.root_module,
});

const run_main_tests = b.addRunArtifact(main_tests);
Expand Down
8 changes: 7 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.{
.name = "deunicode",
.name = .deunicode,
.version = "0.1.0",
.fingerprint = 0x315001c71c0958c8,
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}
8 changes: 4 additions & 4 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn deunicodeCustomAlloc(allocator: Allocator, s: []const u8, custom_placehol

// reserve a bit more space to avoid reallocations on longer transliterations
// but instead of `+ 16` uses `| 15` to stay in the smallest allocation bucket for short strings
var out = try std.ArrayList(u8).initCapacity(allocator, s.len | 15);
var out = try std.array_list.Managed(u8).initCapacity(allocator, s.len | 15);
defer out.deinit();

const ascii = s[0..ascii_len];
Expand Down Expand Up @@ -179,7 +179,7 @@ pub fn deunicodeCustom(out: []u8, s: []const u8, custom_placeholder: []const u8)
break;
}

std.mem.copy(u8, out[cursor .. cursor + ascii_len], s[0..ascii_len]);
std.mem.copyForwards(u8, out[cursor .. cursor + ascii_len], s[0..ascii_len]);
cursor += ascii_len;

if (ascii_len >= s.len) {
Expand Down Expand Up @@ -208,14 +208,14 @@ pub fn deunicodeCustom(out: []u8, s: []const u8, custom_placeholder: []const u8)
has_next_cache = false;

if (res == null) {
std.mem.copy(u8, out[cursor .. cursor + custom_placeholder.len], custom_placeholder);
std.mem.copyForwards(u8, out[cursor .. cursor + custom_placeholder.len], custom_placeholder);
cursor += custom_placeholder.len;
continue;
}

const chars = res.?;

std.mem.copy(u8, out[cursor .. cursor + chars.len], chars);
std.mem.copyForwards(u8, out[cursor .. cursor + chars.len], chars);
cursor += chars.len;

// true if end
Expand Down
Loading