1 package com.icl.saxon.sort; 2 3 4 11 12 public class StringComparer extends TextComparer { 13 14 19 20 public int compare(Object a, Object b) { 21 char[] a1 = ((String )a).toCharArray(); 22 char[] b1 = ((String )b).toCharArray(); 23 int alen = a1.length; 24 int blen = b1.length; 25 int i = 0; 26 int j = 0; 27 while (true) { 28 if (i==alen && j==blen) return 0; 29 if (i==alen) return -1; 30 if (j==blen) return +1; 31 int diff = a1[i++] - b1[j++]; 32 if (diff!=0) return diff; 33 } 34 } 35 36 44 45 public Comparer setCaseOrder(int caseOrder) { 46 if (caseOrder==LOWERCASE_FIRST) { 47 return new LowercaseFirstComparer(); 48 } 49 if (caseOrder==UPPERCASE_FIRST) { 50 return new UppercaseFirstComparer(); 51 } 52 return this; 53 } 54 55 56 } 57 | Popular Tags |