@@ -901,9 +901,10 @@ public static String removeExtension(String filename) {
901901 * @param filename1 the first filename to query, may be null
902902 * @param filename2 the second filename to query, may be null
903903 * @return true if the filenames are equal, null equals null
904+ * @see IOCase#SENSITIVE
904905 */
905906 public static boolean equals (String filename1 , String filename2 ) {
906- return equals (filename1 , filename2 , false , false );
907+ return equals (filename1 , filename2 , false , IOCase . SENSITIVE );
907908 }
908909
909910 /**
@@ -915,9 +916,10 @@ public static boolean equals(String filename1, String filename2) {
915916 * @param filename1 the first filename to query, may be null
916917 * @param filename2 the second filename to query, may be null
917918 * @return true if the filenames are equal, null equals null
919+ * @see IOCase#SYSTEM
918920 */
919921 public static boolean equalsOnSystem (String filename1 , String filename2 ) {
920- return equals (filename1 , filename2 , true , false );
922+ return equals (filename1 , filename2 , false , IOCase . SYSTEM );
921923 }
922924
923925 //-----------------------------------------------------------------------
@@ -930,9 +932,10 @@ public static boolean equalsOnSystem(String filename1, String filename2) {
930932 * @param filename1 the first filename to query, may be null
931933 * @param filename2 the second filename to query, may be null
932934 * @return true if the filenames are equal, null equals null
935+ * @see IOCase#SENSITIVE
933936 */
934937 public static boolean equalsNormalized (String filename1 , String filename2 ) {
935- return equals (filename1 , filename2 , false , true );
938+ return equals (filename1 , filename2 , true , IOCase . SENSITIVE );
936939 }
937940
938941 /**
@@ -946,41 +949,38 @@ public static boolean equalsNormalized(String filename1, String filename2) {
946949 * @param filename1 the first filename to query, may be null
947950 * @param filename2 the second filename to query, may be null
948951 * @return true if the filenames are equal, null equals null
952+ * @see IOCase#SYSTEM
949953 */
950954 public static boolean equalsNormalizedOnSystem (String filename1 , String filename2 ) {
951- return equals (filename1 , filename2 , true , true );
955+ return equals (filename1 , filename2 , true , IOCase . SYSTEM );
952956 }
953957
954958 /**
955- * Checks whether two filenames are equal after both have been normalized
956- * and optionally using the case rules of the system.
957- * <p>
958- * Both filenames are first passed to {@link #normalize(String)}.
959+ * Checks whether two filenames are equal, optionally normalizing and providing
960+ * control over the case-sensitivity.
959961 *
960962 * @param filename1 the first filename to query, may be null
961963 * @param filename2 the second filename to query, may be null
962- * @param system whether to use the system (windows or unix)
963964 * @param normalized whether to normalize the filenames
965+ * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive
964966 * @return true if the filenames are equal, null equals null
967+ * @since Commons IO 1.3
965968 */
966- private static boolean equals (
969+ public static boolean equals (
967970 String filename1 , String filename2 ,
968- boolean system , boolean normalized ) {
969- if (filename1 == filename2 ) {
970- return true ;
971- }
971+ boolean normalized , IOCase caseSensitivity ) {
972+
972973 if (filename1 == null || filename2 == null ) {
973- return false ;
974+ return filename1 == filename2 ;
974975 }
975976 if (normalized ) {
976977 filename1 = normalize (filename1 );
977978 filename2 = normalize (filename2 );
978979 }
979- if (system && isSystemWindows ()) {
980- return filename1 .equalsIgnoreCase (filename2 );
981- } else {
982- return filename1 .equals (filename2 );
980+ if (caseSensitivity == null ) {
981+ caseSensitivity = IOCase .SENSITIVE ;
983982 }
983+ return caseSensitivity .checkEquals (filename1 , filename2 );
984984 }
985985
986986 //-----------------------------------------------------------------------
@@ -1068,7 +1068,7 @@ public static boolean isExtension(String filename, Collection extensions) {
10681068 * The wildcard matcher uses the characters '?' and '*' to represent a
10691069 * single or multiple wildcard characters.
10701070 * This is the same as often found on Dos/Unix command lines.
1071- * The extension check is case-sensitive.
1071+ * The check is case-sensitive always .
10721072 * <pre>
10731073 * wildcardMatch("c.txt", "*.txt") --> true
10741074 * wildcardMatch("c.txt", "*.jpg") --> false
@@ -1080,9 +1080,10 @@ public static boolean isExtension(String filename, Collection extensions) {
10801080 * @param filename the filename to match on
10811081 * @param wildcardMatcher the wildcard string to match against
10821082 * @return true if the filename matches the wilcard string
1083+ * @see IOCase#SENSITIVE
10831084 */
10841085 public static boolean wildcardMatch (String filename , String wildcardMatcher ) {
1085- return wildcardMatch (filename , wildcardMatcher , false );
1086+ return wildcardMatch (filename , wildcardMatcher , IOCase . SENSITIVE );
10861087 }
10871088
10881089 /**
@@ -1104,32 +1105,34 @@ public static boolean wildcardMatch(String filename, String wildcardMatcher) {
11041105 * @param filename the filename to match on
11051106 * @param wildcardMatcher the wildcard string to match against
11061107 * @return true if the filename matches the wilcard string
1108+ * @see IOCase#SYSTEM
11071109 */
11081110 public static boolean wildcardMatchOnSystem (String filename , String wildcardMatcher ) {
1109- return wildcardMatch (filename , wildcardMatcher , true );
1111+ return wildcardMatch (filename , wildcardMatcher , IOCase . SYSTEM );
11101112 }
11111113
11121114 /**
1113- * Checks a filename to see if it matches the specified wildcard matcher.
1115+ * Checks a filename to see if it matches the specified wildcard matcher
1116+ * allowing control over case-sensitivity.
11141117 * <p>
11151118 * The wildcard matcher uses the characters '?' and '*' to represent a
11161119 * single or multiple wildcard characters.
11171120 *
11181121 * @param filename the filename to match on
11191122 * @param wildcardMatcher the wildcard string to match against
1120- * @param system whether to use the system (windows or unix)
1123+ * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive
11211124 * @return true if the filename matches the wilcard string
1125+ * @since Commons IO 1.3
11221126 */
1123- private static boolean wildcardMatch (String filename , String wildcardMatcher , boolean system ) {
1127+ public static boolean wildcardMatch (String filename , String wildcardMatcher , IOCase caseSensitivity ) {
11241128 if (filename == null && wildcardMatcher == null ) {
11251129 return true ;
11261130 }
11271131 if (filename == null || wildcardMatcher == null ) {
11281132 return false ;
11291133 }
1130- if (system && isSystemWindows ()) {
1131- filename = filename .toLowerCase ();
1132- wildcardMatcher = wildcardMatcher .toLowerCase ();
1134+ if (caseSensitivity == null ) {
1135+ caseSensitivity = IOCase .SENSITIVE ;
11331136 }
11341137 String [] wcs = splitOnTokens (wildcardMatcher );
11351138 boolean anyChars = false ;
@@ -1176,7 +1179,7 @@ private static boolean wildcardMatch(String filename, String wildcardMatcher, bo
11761179 }
11771180 } else {
11781181 // matching from current position
1179- if (!filename . startsWith ( wcs [wcsIdx ], textIdx )) {
1182+ if (!caseSensitivity . checkRegionMatches ( filename , textIdx , wcs [wcsIdx ])) {
11801183 // couldnt match token
11811184 break ;
11821185 }
0 commit comments