Reuse code already available in StringUtils
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1560756 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6f5f99440e
commit
3eb4be60cf
|
@ -7123,27 +7123,7 @@ public class StringUtils {
|
|||
* @return A number between 0 and 4.
|
||||
*/
|
||||
private static int commonPrefixLength(CharSequence first, CharSequence second) {
|
||||
String shorter;
|
||||
String longer;
|
||||
|
||||
// Determine which String is longer.
|
||||
if (first.length() > second.length()) {
|
||||
longer = first.toString().toLowerCase();
|
||||
shorter = second.toString().toLowerCase();
|
||||
} else {
|
||||
longer = second.toString().toLowerCase();
|
||||
shorter = first.toString().toLowerCase();
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
// Iterate through the shorter string.
|
||||
for (int i = 0; i < shorter.length(); i++) {
|
||||
if (shorter.charAt(i) != longer.charAt(i)) {
|
||||
break;
|
||||
}
|
||||
result++;
|
||||
}
|
||||
final int result = getCommonPrefix(first.toString(), second.toString()).length();
|
||||
|
||||
// Limit the result to 4.
|
||||
return result > 4 ? 4 : result;
|
||||
|
|
Loading…
Reference in New Issue