src/share/classes/java/lang/String.java

Print this page




1228             int n2 = s2.length();
1229             int min = Math.min(n1, n2);
1230             for (int i = 0; i < min; i++) {
1231                 char c1 = s1.charAt(i);
1232                 char c2 = s2.charAt(i);
1233                 if (c1 != c2) {
1234                     c1 = Character.toUpperCase(c1);
1235                     c2 = Character.toUpperCase(c2);
1236                     if (c1 != c2) {
1237                         c1 = Character.toLowerCase(c1);
1238                         c2 = Character.toLowerCase(c2);
1239                         if (c1 != c2) {
1240                             // No overflow because of numeric promotion
1241                             return c1 - c2;
1242                         }
1243                     }
1244                 }
1245             }
1246             return n1 - n2;
1247         }


1248     }
1249 
1250     /**
1251      * Compares two strings lexicographically, ignoring case
1252      * differences. This method returns an integer whose sign is that of
1253      * calling <code>compareTo</code> with normalized versions of the strings
1254      * where case differences have been eliminated by calling
1255      * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
1256      * each character.
1257      * <p>
1258      * Note that this method does <em>not</em> take locale into account,
1259      * and will result in an unsatisfactory ordering for certain locales.
1260      * The java.text package provides <em>collators</em> to allow
1261      * locale-sensitive ordering.
1262      *
1263      * @param   str   the <code>String</code> to be compared.
1264      * @return  a negative integer, zero, or a positive integer as the
1265      *          specified String is greater than, equal to, or less
1266      *          than this String, ignoring case considerations.
1267      * @see     java.text.Collator#compare(String, String)




1228             int n2 = s2.length();
1229             int min = Math.min(n1, n2);
1230             for (int i = 0; i < min; i++) {
1231                 char c1 = s1.charAt(i);
1232                 char c2 = s2.charAt(i);
1233                 if (c1 != c2) {
1234                     c1 = Character.toUpperCase(c1);
1235                     c2 = Character.toUpperCase(c2);
1236                     if (c1 != c2) {
1237                         c1 = Character.toLowerCase(c1);
1238                         c2 = Character.toLowerCase(c2);
1239                         if (c1 != c2) {
1240                             // No overflow because of numeric promotion
1241                             return c1 - c2;
1242                         }
1243                     }
1244                 }
1245             }
1246             return n1 - n2;
1247         }
1248         
1249         private Object readResolve() { return CASE_INSENSITIVE_ORDER; }
1250     }
1251 
1252     /**
1253      * Compares two strings lexicographically, ignoring case
1254      * differences. This method returns an integer whose sign is that of
1255      * calling <code>compareTo</code> with normalized versions of the strings
1256      * where case differences have been eliminated by calling
1257      * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
1258      * each character.
1259      * <p>
1260      * Note that this method does <em>not</em> take locale into account,
1261      * and will result in an unsatisfactory ordering for certain locales.
1262      * The java.text package provides <em>collators</em> to allow
1263      * locale-sensitive ordering.
1264      *
1265      * @param   str   the <code>String</code> to be compared.
1266      * @return  a negative integer, zero, or a positive integer as the
1267      *          specified String is greater than, equal to, or less
1268      *          than this String, ignoring case considerations.
1269      * @see     java.text.Collator#compare(String, String)