1 | static betterCIComparator_es_C betterCIComparator_es_instance; |
2 | |
3 | static betterCIComparator_es_C betterCIComparator_es() { |
4 | if (betterCIComparator_es_instance == null) |
5 | betterCIComparator_es_instance = new betterCIComparator_es_C; |
6 | ret betterCIComparator_es_instance; |
7 | } |
8 | |
9 | sclass betterCIComparator_es_C implements Comparator<ES> { |
10 | public int compare(ES e1, ES e2) { |
11 | S s1 = getVar(e1), s2 = getVar(e2); |
12 | if (s1 == null) ret s2 == null ? 0 : -1; |
13 | if (s2 == null) ret 1; |
14 | |
15 | int n1 = s1.length(); |
16 | int n2 = s2.length(); |
17 | int min = Math.min(n1, n2); |
18 | for (int i = 0; i < min; i++) { |
19 | char c1 = s1.charAt(i); |
20 | char c2 = s2.charAt(i); |
21 | if (c1 != c2) { |
22 | c1 = Character.toUpperCase(c1); |
23 | c2 = Character.toUpperCase(c2); |
24 | if (c1 != c2) { |
25 | c1 = Character.toLowerCase(c1); |
26 | c2 = Character.toLowerCase(c2); |
27 | if (c1 != c2) { |
28 | // No overflow because of numeric promotion |
29 | return c1 - c2; |
30 | } |
31 | } |
32 | } |
33 | } |
34 | return n1 - n2; |
35 | } |
36 | } |
Began life as a copy of #1014136
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1023202 |
Snippet name: | betterCIComparator_es (compared to String.CASE_INSENSITIVE_ORDER, allows nulls) |
Eternal ID of this version: | #1023202/1 |
Text MD5: | 88a23a4be22f9e503933831443a603a3 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-05-16 19:54:25 |
Source code size: | 1145 bytes / 36 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 276 / 320 |
Referenced in: | [show references] |