1 package com.icl.saxon.sort; 2 3 6 13 14 public class Compare_en extends TextComparer { 15 16 18 private static String supp = 19 "AAAAAAACEEEEIIII[NOOOOO*OUUUUY]Saaaaaaaceeeeiiii{nooooo*ouuuuy}y"; 20 21 int caseOrder = UPPERCASE_FIRST; 22 23 30 31 public int compare(Object a, Object b) { 32 33 char[] a1 = ((String )a).toCharArray(); 34 char[] b1 = ((String )b).toCharArray(); 35 int alen = a1.length; 36 int blen = b1.length; 37 38 for (int k=0; k<alen; k++) { 40 int code = (int)a1[k]; 41 if (code>=192 && code<=255) { 42 a1[k] = supp.charAt(code-192); 43 } 44 } 45 for (int k=0; k<blen; k++) { 46 int code = (int)b1[k]; 47 if (code>=192 && code<=255) { 48 b1[k] = supp.charAt(code-192); 49 } 50 } 51 int i = 0; 52 int j = 0; 53 54 while (true) { 56 if (i==alen && j==blen) break; 57 if (i==alen) return -1; 58 if (j==blen) return +1; 59 int diff = Character.toLowerCase(a1[i]) - 60 Character.toLowerCase(b1[j]); 61 i++; 62 j++; 63 if (diff!=0) return diff; 64 } 65 66 68 a1 = ((String )a).toCharArray(); 69 b1 = ((String )b).toCharArray(); 70 i = 0; 71 j = 0; 72 while (true) { 73 if (i==alen && j==blen) break; 74 if (i==alen) return -1; 75 if (j==blen) return +1; 76 int diff = Character.toLowerCase(a1[i]) - 77 Character.toLowerCase(b1[j]); 78 i++; 79 j++; 80 if (diff!=0) return diff; 81 } 82 83 85 i = 0; 86 j = 0; 87 while (true) { 88 if (i==alen) return 0; 89 int diff = a1[i++] - b1[j++]; 90 if (diff!=0) { 91 if (caseOrder==LOWERCASE_FIRST) { 92 return (Character.isLowerCase(a1[i-1]) ? -1 : +1); 93 } else { 94 return (Character.isUpperCase(a1[i-1]) ? -1 : +1); 95 } 96 } 97 } 98 99 } 100 101 public Comparer setCaseOrder(int caseOrder) { 102 this.caseOrder = caseOrder; 103 return this; 104 } 105 106 } 107 | Popular Tags |