| author | |
| committer | |
| log | 25f49eccc782ade9c0a32ba80c7e7c8f44353f2a |
| tree | 497bc102f2e6baa9760badf85402c7bfb33ad156 |
| parent | 35065b703a0912fd39d56f91f7e4f8c886b9ab63 |
| signature |
3 files changed, 16 insertions(+), 8 deletions(-)
scripts/UnicodeData.zig+7-4| ... | ... | @@ -9,6 +9,9 @@ pub usingnamespace common.Main(struct { |
| 9 | 9 | pub const dest_header = |
| 10 | 10 | \\const ucd = @import("./lib.zig"); |
| 11 | 11 | \\const std = @import("std"); |
| 12 | \\const extras = @import("extras"); | |
| 13 | \\ | |
| 14 | \\pub const data_soa = extras.StaticMultiList(Codepoint).initComptime(&data); | |
| 12 | 15 | \\ |
| 13 | 16 | \\pub const Codepoint = struct { |
| 14 | 17 | \\ u21, // U+ code |
| ... | ... | @@ -49,7 +52,7 @@ pub usingnamespace common.Main(struct { |
| 49 | 52 | \\}; |
| 50 | 53 | \\ |
| 51 | 54 | \\pub fn find(cp: u21) Codepoint { |
| 52 | \\ return data[binarySearchClosest(Codepoint, &data, cp, compare)]; | |
| 55 | \\ return data[binarySearchClosest(u21, data_soa[0], cp, compare)]; | |
| 53 | 56 | \\} |
| 54 | 57 | \\ |
| 55 | 58 | \\fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, comptime compareFn: fn (@TypeOf(context), T) std.math.Order) usize { |
| ... | ... | @@ -67,9 +70,9 @@ pub usingnamespace common.Main(struct { |
| 67 | 70 | \\ return high; |
| 68 | 71 | \\} |
| 69 | 72 | \\ |
| 70 | \\pub fn compare(needle: u21, row: Codepoint) std.math.Order { | |
| 71 | \\ if (needle < row[0]) return .lt; | |
| 72 | \\ if (needle > row[0]) return .gt; | |
| 73 | \\pub fn compare(needle: u21, row: u21) std.math.Order { | |
| 74 | \\ if (needle < row) return .lt; | |
| 75 | \\ if (needle > row) return .gt; | |
| 73 | 76 | \\ return .eq; |
| 74 | 77 | \\} |
| 75 | 78 | \\ |
src/unicode_data.zig+7-4| ... | ... | @@ -7,6 +7,9 @@ |
| 7 | 7 | |
| 8 | 8 | const ucd = @import("./lib.zig"); |
| 9 | 9 | const std = @import("std"); |
| 10 | const extras = @import("extras"); | |
| 11 | ||
| 12 | pub const data_soa = extras.StaticMultiList(Codepoint).initComptime(&data).items; | |
| 10 | 13 | |
| 11 | 14 | pub const Codepoint = struct { |
| 12 | 15 | u21, // U+ code |
| ... | ... | @@ -47,7 +50,7 @@ pub const Decomposition = enum { |
| 47 | 50 | }; |
| 48 | 51 | |
| 49 | 52 | pub fn find(cp: u21) Codepoint { |
| 50 | return data[binarySearchClosest(Codepoint, &data, cp, compare)]; | |
| 53 | return data[binarySearchClosest(u21, data_soa[0], cp, compare)]; | |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | 56 | fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, comptime compareFn: fn (@TypeOf(context), T) std.math.Order) usize { |
| ... | ... | @@ -65,9 +68,9 @@ fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, com |
| 65 | 68 | return high; |
| 66 | 69 | } |
| 67 | 70 | |
| 68 | pub fn compare(needle: u21, row: Codepoint) std.math.Order { | |
| 69 | if (needle < row[0]) return .lt; | |
| 70 | if (needle > row[0]) return .gt; | |
| 71 | pub fn compare(needle: u21, row: u21) std.math.Order { | |
| 72 | if (needle < row) return .lt; | |
| 73 | if (needle > row) return .gt; | |
| 71 | 74 | return .eq; |
| 72 | 75 | } |
| 73 | 76 |
zig.mod+2| ... | ... | @@ -3,6 +3,8 @@ name: unicode-ucd |
| 3 | 3 | main: src/lib.zig |
| 4 | 4 | license: MIT |
| 5 | 5 | description: Zig bindings for the Unicode Character Database |
| 6 | dependencies: | |
| 7 | - src: git https://github.com/nektro/zig-extras | |
| 6 | 8 | root_dependencies: |
| 7 | 9 | - src: git https://github.com/nektro/zfetch |
| 8 | 10 | - src: git https://github.com/nektro/zig-ansi |