diff options
author | sterni <sternenseemann@systemli.org> | 2023-08-05T13·39+0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2023-08-09T12·12+0000 |
commit | 984ea69386a47e753c4129e2a6230aa60b4584cd (patch) | |
tree | bab3642e070d41d5901c1c73a839ff1c03b7313a /users/sterni/nix/utf8/default.nix | |
parent | dbdb2575cfd12b7b41fbf12547592d00819c7546 (diff) |
refactor(users/sterni/nix): move generic number operation into num r/6477
We omit type checks for performance reasons in most places currently, so the library grouping is important in showing people what to use for what sort of input. The moved functions make sense to use with floats as well, so we'll move them to the num library. Some of the remaining functions could theoretically be adapted and moved, but aren't for now. Change-Id: Ifdecaa60be594f4438b2a58b9ea6445e2da080e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9007 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'users/sterni/nix/utf8/default.nix')
-rw-r--r-- | users/sterni/nix/utf8/default.nix | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/users/sterni/nix/utf8/default.nix b/users/sterni/nix/utf8/default.nix index 71c846c0421e..e76695f128b2 100644 --- a/users/sterni/nix/utf8/default.nix +++ b/users/sterni/nix/utf8/default.nix @@ -6,6 +6,7 @@ let char flow fun + num int string util @@ -46,17 +47,17 @@ let # byte position as an index starting with 0 pos: let - defaultRange = int.inRange 128 191; + defaultRange = num.inRange 128 191; secondBytePredicate = flow.switch first [ - [ (int.inRange 194 223) defaultRange ] # C2..DF - [ 224 (int.inRange 160 191) ] # E0 - [ (int.inRange 225 236) defaultRange ] # E1..EC - [ 237 (int.inRange 128 159) ] # ED - [ (int.inRange 238 239) defaultRange ] # EE..EF - [ 240 (int.inRange 144 191) ] # F0 - [ (int.inRange 241 243) defaultRange ] # F1..F3 - [ 244 (int.inRange 128 143) ] # F4 + [ (num.inRange 194 223) defaultRange ] # C2..DF + [ 224 (num.inRange 160 191) ] # E0 + [ (num.inRange 225 236) defaultRange ] # E1..EC + [ 237 (num.inRange 128 159) ] # ED + [ (num.inRange 238 239) defaultRange ] # EE..EF + [ 240 (num.inRange 144 191) ] # F0 + [ (num.inRange 241 243) defaultRange ] # F1..F3 + [ 244 (num.inRange 128 143) ] # F4 [ (fun.const true) null ] ]; @@ -225,10 +226,10 @@ let # Note that this doesn't check if the Unicode codepoint is allowed, # but rather allows all theoretically UTF-8-encodeable ones. count = flow.switch cp [ - [ (int.inRange 0 127) 1 ] # 00000000 0xxxxxxx - [ (int.inRange 128 2047) 2 ] # 00000yyy yyxxxxxx - [ (int.inRange 2048 65535) 3 ] # zzzzyyyy yyxxxxxx - [ (int.inRange 65536 1114111) 4 ] # 000uuuuu zzzzyyyy yyxxxxxx, + [ (num.inRange 0 127) 1 ] # 00000000 0xxxxxxx + [ (num.inRange 128 2047) 2 ] # 00000yyy yyxxxxxx + [ (num.inRange 2048 65535) 3 ] # zzzzyyyy yyxxxxxx + [ (num.inRange 65536 1114111) 4 ] # 000uuuuu zzzzyyyy yyxxxxxx, # capped at U+10FFFF [ (fun.const true) (builtins.throw invalidCodepointMsg) ] |