zigzedd/anyascii.zig
[MIRROR] Zig port of C implementation of anyascii.
This repository allows to use anyascii C implementation from zig, with a helper function utf8ToAscii
to easily convert any UTF-8 encoded string in an ASCII-only string.
Current version of anyascii: 2023-08-01
.
anyascii
const std = @import("std");
const anyascii = @import("anyascii").anyascii;
// A single UTF-8 codepoint to its ASCII equivalent.
const ascii = try anyascii(allocator, try std.unicode.utf8Decode("Φ"));
defer allocator.free(ascii);
std.debug.print("{s}", .{ascii}); // Output: "F".
utf8ToAscii
const std = @import("std");
const utf8ToAscii = @import("anyascii").utf8ToAscii;
// A full string of UTF-8 characters to ASCII characters.
const ascii = try utf8ToAscii(allocator, "Blöße");
defer allocator.free(ascii);
std.debug.print("{s}", .{ascii}); // Output: "Blosse".
In your project directory:
zig fetch --save https://code.zeptotech.net/zedd/anyascii.zig/archive/v1.1.0.tar.gz
In build.zig
:
// Add anyascii.zig dependency.
const anyascii = b.dependency("anyascii.zig", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("anyascii", anyascii.module("anyascii"));
Taken from official anyascii description.
AnyAscii provides ASCII-only replacement strings for practically all Unicode characters. Text is converted character-by-character without considering the context. The mappings for each script are based on popular existing romanization systems. Symbolic characters are converted based on their meaning or appearance. All ASCII characters in the input are left unchanged, every other character is replaced with printable ASCII characters.