Download Jar. Libraryless. Click here for Pure Java version (944L/7K).
1 | !7 |
2 | |
3 | static int compareUtf8(byte[] left, byte[] right) {
|
4 | int n = min(left.length, right.length); |
5 | for (int i = 0; i < n; i++) {
|
6 | int a = left[i] & 0xff; |
7 | int b = right[i] & 0xff; |
8 | if (a != b) ret a-b; |
9 | } |
10 | ret left.length - right.length; |
11 | } |
12 | |
13 | p {
|
14 | bool ok = true; |
15 | repeat 10000 {
|
16 | //S a = aGlobalID(), b = aGlobalID(); |
17 | //S a = totallyRandomChars(10), b = totallyRandomChars(10); |
18 | S a = fairlyRandomChars(10), b = fairlyRandomChars(10); |
19 | try {
|
20 | assertEquals(sign(a.compareTo(b)), sign(compareUtf8(toUtf8(a), toUtf8(b)))); |
21 | } catch print short e {
|
22 | print(toHex(toUtf8(a)) + " " + toHex(toUtf8(b))); |
23 | ok = false; |
24 | } |
25 | } |
26 | if (ok) print("OK!");
|
27 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1011477 |
| Snippet name: | Test utf8 byte array comparator [seems to work] |
| Eternal ID of this version: | #1011477/7 |
| Text MD5: | b951805bdd599b11f616fc1a644ba684 |
| Transpilation MD5: | cd485427c50317a6bc5a783c730b8e7d |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code (desktop) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-10-30 02:17:07 |
| Source code size: | 714 bytes / 27 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 774 / 1631 |
| Version history: | 6 change(s) |
| Referenced in: | [show references] |