From: Matt I. <mat...@us...> - 2004-02-10 00:27:16
|
Update of /cvsroot/ant-contrib/ant-contrib/src/net/sf/antcontrib/property In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28500 Modified Files: SortList.java Log Message: Fix defect #883360. Using case insensitive sort was giving back all lowercase list items. it should sort case insensitive, but give back list items in the same case as they were input. Index: SortList.java =================================================================== RCS file: /cvsroot/ant-contrib/ant-contrib/src/net/sf/antcontrib/property/SortList.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SortList.java 4 Feb 2004 16:24:15 -0000 1.9 --- SortList.java 9 Feb 2004 22:07:18 -0000 1.10 *************** *** 23,26 **** --- 23,27 ---- import java.util.StringTokenizer; import java.util.Vector; + import java.util.Locale; import org.apache.tools.ant.BuildException; *************** *** 98,101 **** --- 99,103 ---- int low, int high, + boolean caseSensitive, boolean numeric) { int length = high - low; *************** *** 105,109 **** for (int i=low; i<high; i++) for (int j=i; j>low && ! compare(dest[j-1],dest[j],numeric)>0; j--) swap(dest, j, j-1); return; --- 107,111 ---- for (int i=low; i<high; i++) for (int j=i; j>low && ! compare(dest[j-1],dest[j], caseSensitive, numeric)>0; j--) swap(dest, j, j-1); return; *************** *** 112,121 **** // Recursively sort halves of dest into src int mid = (low + high)/2; ! mergeSort(dest, src, low, mid, numeric); ! mergeSort(dest, src, mid, high, numeric); // If list is already sorted, just copy from src to dest. This is an // optimization that results in faster sorts for nearly ordered lists. ! if (compare(src[mid-1], src[mid], numeric) <= 0) { System.arraycopy(src, low, dest, low, length); return; --- 114,123 ---- // Recursively sort halves of dest into src int mid = (low + high)/2; ! mergeSort(dest, src, low, mid, caseSensitive, numeric); ! mergeSort(dest, src, mid, high, caseSensitive, numeric); // If list is already sorted, just copy from src to dest. This is an // optimization that results in faster sorts for nearly ordered lists. ! if (compare(src[mid-1], src[mid], caseSensitive, numeric) <= 0) { System.arraycopy(src, low, dest, low, length); return; *************** *** 124,128 **** // Merge sorted halves (now in src) into dest for(int i = low, p = low, q = mid; i < high; i++) { ! if (q>=high || p<mid && compare(src[p], src[q], numeric)<=0) dest[i] = src[p++]; else --- 126,130 ---- // Merge sorted halves (now in src) into dest for(int i = low, p = low, q = mid; i < high; i++) { ! if (q>=high || p<mid && compare(src[p], src[q], caseSensitive, numeric)<=0) dest[i] = src[p++]; else *************** *** 133,136 **** --- 135,139 ---- private static int compare(String s1, String s2, + boolean casesensitive, boolean numeric) { *************** *** 148,155 **** res = 1; } ! else { res = s1.compareTo(s2); } return res; --- 151,163 ---- res = 1; } ! else if (casesensitive) { res = s1.compareTo(s2); } + else + { + Locale l = Locale.getDefault(); + res = s1.toLowerCase(l).compareTo(s2.toLowerCase(l)); + } return res; *************** *** 269,281 **** { String s[] = (String[])(vec.toArray(new String[vec.size()])); - if (! casesensitive) - { - for (int i=0;i<s.length;i++) - s[i] = s[i].toLowerCase(); - } - propList = new String[s.length]; System.arraycopy(s, 0, propList, 0, s.length); ! mergeSort(s, propList, 0, s.length, numeric); } --- 277,283 ---- { String s[] = (String[])(vec.toArray(new String[vec.size()])); propList = new String[s.length]; System.arraycopy(s, 0, propList, 0, s.length); ! mergeSort(s, propList, 0, s.length, casesensitive, numeric); } |