Download Jar. Libraryless. Click here for Pure Java version (944L/7K).
!7 static int compareUtf8(byte[] left, byte[] right) { int n = min(left.length, right.length); for (int i = 0; i < n; i++) { int a = left[i] & 0xff; int b = right[i] & 0xff; if (a != b) ret a-b; } ret left.length - right.length; } p { bool ok = true; repeat 10000 { //S a = aGlobalID(), b = aGlobalID(); //S a = totallyRandomChars(10), b = totallyRandomChars(10); S a = fairlyRandomChars(10), b = fairlyRandomChars(10); try { assertEquals(sign(a.compareTo(b)), sign(compareUtf8(toUtf8(a), toUtf8(b)))); } catch print short e { print(toHex(toUtf8(a)) + " " + toHex(toUtf8(b))); ok = false; } } if (ok) print("OK!"); }
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: | 527 / 1074 |
Version history: | 6 change(s) |
Referenced in: | [show references] |