Lines 2939-2962
Link Here
|
2939 |
char[] prefix, |
2939 |
char[] prefix, |
2940 |
char[] name, |
2940 |
char[] name, |
2941 |
boolean isCaseSensitive) { |
2941 |
boolean isCaseSensitive) { |
|
|
2942 |
return prefixEquals(prefix, name, isCaseSensitive, 0); |
2943 |
} |
2944 |
|
2945 |
/** |
2946 |
* Answers true if the given name, starting from the given index, starts with the given prefix, |
2947 |
* false otherwise. isCaseSensitive is used to find out whether or not the comparison should be |
2948 |
* case sensitive. |
2949 |
* <br> |
2950 |
* <br> |
2951 |
* For example: |
2952 |
* <ol> |
2953 |
* <li><pre> |
2954 |
* prefix = { 'a' , 'B' } |
2955 |
* name = { 'c', 'd', 'a' , 'b', 'b', 'a', 'b', 'a' } |
2956 |
* startIndex = 2 |
2957 |
* isCaseSensitive = false |
2958 |
* result => true |
2959 |
* </pre> |
2960 |
* </li> |
2961 |
* <li><pre> |
2962 |
* prefix = { 'a' , 'B' } |
2963 |
* name = { 'c', 'd', 'a' , 'b', 'b', 'a', 'b', 'a' } |
2964 |
* startIndex = 2 |
2965 |
* isCaseSensitive = true |
2966 |
* result => false |
2967 |
* </pre> |
2968 |
* </li> |
2969 |
* </ol> |
2970 |
* |
2971 |
* @param prefix the given prefix |
2972 |
* @param name the given name |
2973 |
* @param isCaseSensitive to find out whether or not the comparison should be case sensitive |
2974 |
* @param startIndex index from which the prefix should be searched in the name |
2975 |
* @return true if the given name starts with the given prefix, false otherwise |
2976 |
* @throws NullPointerException if the given name is null or if the given prefix is null |
2977 |
* @since 3.7 |
2978 |
*/ |
2979 |
public static final boolean prefixEquals( |
2980 |
char[] prefix, |
2981 |
char[] name, |
2982 |
boolean isCaseSensitive, |
2983 |
int startIndex) { |
2942 |
|
2984 |
|
2943 |
int max = prefix.length; |
2985 |
int max = prefix.length; |
2944 |
if (name.length < max) |
2986 |
if (name.length - startIndex < max) |
2945 |
return false; |
2987 |
return false; |
2946 |
if (isCaseSensitive) { |
2988 |
if (isCaseSensitive) { |
2947 |
for (int i = max; |
2989 |
for (int i = max; --i >= 0;) // assumes the prefix is not larger than the name |
2948 |
--i >= 0; |
2990 |
if (prefix[i] != name[startIndex + i]) |
2949 |
) // assumes the prefix is not larger than the name |
|
|
2950 |
if (prefix[i] != name[i]) |
2951 |
return false; |
2991 |
return false; |
2952 |
return true; |
2992 |
return true; |
2953 |
} |
2993 |
} |
2954 |
|
2994 |
|
2955 |
for (int i = max; |
2995 |
for (int i = max; --i >= 0;) // assumes the prefix is not larger than the name |
2956 |
--i >= 0; |
|
|
2957 |
) // assumes the prefix is not larger than the name |
2958 |
if (ScannerHelper.toLowerCase(prefix[i]) |
2996 |
if (ScannerHelper.toLowerCase(prefix[i]) |
2959 |
!= ScannerHelper.toLowerCase(name[i])) |
2997 |
!= ScannerHelper.toLowerCase(name[startIndex + i])) |
2960 |
return false; |
2998 |
return false; |
2961 |
return true; |
2999 |
return true; |
2962 |
} |
3000 |
} |