~alva/moj

cb3e901be031f302fcad1ee90469d9931bc3df06 — ugla 2 years ago e28ba72
Bold match within name
2 files changed, 20 insertions(+), 15 deletions(-)

M src/UnicodeData.txt
M src/main.zig
M src/UnicodeData.txt => src/UnicodeData.txt +1 -1
@@ 34623,4 34623,4 @@ E01EF;VARIATION SELECTOR-256;Mn;0;NSM;;;;;N;;;;;
F0000;<Plane 15 Private Use, First>;Co;0;L;;;;;N;;;;;
FFFFD;<Plane 15 Private Use, Last>;Co;0;L;;;;;N;;;;;
100000;<Plane 16 Private Use, First>;Co;0;L;;;;;N;;;;;
10FFFD;<Plane 16 Private Use, Last>;Co;0;L;;;;;N;;;;;
10FFFD;<Plane 16 Private Use, Last>;Co;0;L;;;;;N;;;;;
\ No newline at end of file

M src/main.zig => src/main.zig +19 -14
@@ 22,24 22,29 @@ pub fn main() anyerror!void {
fn writeMatches(writer: anytype, needle: []const u8) !void {
    var split_it = std.mem.split(u8, UNICODE_DATA, "\n");

    while (split_it.next()) |line| {
        if (std.mem.indexOf(u8, line, needle)) |_| {
            try writeMatch(writer, line);
        }
    }
    while (split_it.next()) |line|
        try writeMatch(writer, line, needle);
}

fn writeMatch(writer: anytype, line: []const u8) !void {
fn writeMatch(writer: anytype, line: []const u8, needle: []const u8) !void {
    var utf8_char: [8]u8 = undefined;
    var col_it = std.mem.split(u8, line, ";");
    const cp = try std.fmt.parseInt(u21, col_it.next() orelse return error.BongosData, 16);
    const len = try std.unicode.utf8Encode(cp, &utf8_char);
    try writer.print("{s} code: 0x{x:<6} name: {s:<14} category: {s}\n", .{
        utf8_char[0..len],
        cp,
        col_it.next() orelse return error.BongosData,
        col_it.next() orelse return error.BongosData,
    });
    const code = col_it.next() orelse return error.MissingCode;
    const name = col_it.next() orelse return error.MissingName;

    if (std.mem.indexOf(u8, name, needle)) |idx| {
        const category = col_it.next() orelse return error.MissingCategory;
        const cp = try std.fmt.parseInt(u21, code, 16);
        const len = try std.unicode.utf8Encode(cp, &utf8_char);
        try writer.print("{s} code: 0x{x:<6} name: {s}\x1b[1m{s}\x1b[0m{s} category: {s}\n", .{
            utf8_char[0..len],
            cp,
            name[0..idx],
            name[idx .. idx + needle.len],
            name[idx + needle.len ..],
            category,
        });
    }
}

fn badToUpper(c: u8) u8 {