Replace non-standard name processing with StringUtils
@@ -38,6 +38,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.CheckForNull;
+import org.apache.commons.lang.StringUtils;
/**
* Data representation of the auto-completion candidates.
@@ -118,36 +119,28 @@ public class AutoCompletionCandidates implements HttpResponse {
@Override
public void onItem(Item i) {
- String n = contextualNameOf(i);
+ String itemName = contextualNameOf(i);
//Check user's setting on whether to do case sensitive comparison, configured in user -> configure
//This is the same setting that is used by the global search field, should be consistent throughout
//the whole application.
boolean caseInsensitive = UserSearchProperty.isCaseInsensitive();
- String hay = n;
- String needle = value;
-
- if(caseInsensitive) {
- hay = hay.toLowerCase();
- needle = needle.toLowerCase();
- }
-
- if ((hay.startsWith(needle) || needle.startsWith(hay))
+ if ((startsWithImpl(itemName, value, caseInsensitive) || startsWithImpl(value, itemName, caseInsensitive))
// 'foobar' is a valid candidate if the current value is 'foo'.
// Also, we need to visit 'foo' if the current value is 'foo/bar'
- && (needle.length()>hay.length() || !hay.substring(needle.length()).contains("/"))
+ && (value.length()> itemName.length() || !itemName.substring(value.length()).contains("/"))
// but 'foobar/zot' isn't if the current value is 'foo'
// we'll first show 'foobar' and then wait for the user to type '/' to show the rest
&& i.hasPermission(Item.READ)
// and read permission required
) {
- if (type.isInstance(i) && hay.startsWith(needle))
- candidates.add(n);
+ if (type.isInstance(i) && startsWithImpl(itemName, value, caseInsensitive))
+ candidates.add(itemName);
// recurse
String oldPrefix = prefix;
- prefix = n;
+ prefix = itemName;
super.onItem(i);
prefix = oldPrefix;
}
@@ -176,4 +169,8 @@ public class AutoCompletionCandidates implements HttpResponse {
return candidates;
}
+
+ private static boolean startsWithImpl(String str, String prefix, boolean ignoreCase) {
+ return ignoreCase ? StringUtils.startsWithIgnoreCase(str, prefix) : str.startsWith(prefix);
+ }
}
