summaryrefslogtreecommitdiffstats
path: root/src/com/gitblit/utils/StringUtils.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-09-12 15:37:55 -0400
committerJames Moger <james.moger@gitblit.com>2011-09-12 15:37:55 -0400
commit831469ba89ea8bca3bfbd1d662dbdd2c9f233798 (patch)
treeb36d770bcaf0c6a2ab8caf865f04ff60734ed71f /src/com/gitblit/utils/StringUtils.java
parentcbf59502795be12dc0015e05523076a9561df807 (diff)
downloadgitblit-831469ba89ea8bca3bfbd1d662dbdd2c9f233798.tar.gz
gitblit-831469ba89ea8bca3bfbd1d662dbdd2c9f233798.zip
Largely completed, uber-cool federation feature.
Diffstat (limited to 'src/com/gitblit/utils/StringUtils.java')
-rw-r--r--src/com/gitblit/utils/StringUtils.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java
index bb1928a2..77d3cbbc 100644
--- a/src/com/gitblit/utils/StringUtils.java
+++ b/src/com/gitblit/utils/StringUtils.java
@@ -342,4 +342,57 @@ public class StringUtils {
}
return strings;
}
+
+ /**
+ * Validates that a name is composed of letters, digits, or limited other
+ * characters.
+ *
+ * @param name
+ * @return the first invalid character found or null if string is acceptable
+ */
+ public static Character findInvalidCharacter(String name) {
+ char[] validChars = { '/', '.', '_', '-' };
+ for (char c : name.toCharArray()) {
+ if (!Character.isLetterOrDigit(c)) {
+ boolean ok = false;
+ for (char vc : validChars) {
+ ok |= c == vc;
+ }
+ if (!ok) {
+ return c;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Simple fuzzy string comparison. This is a case-insensitive check. A
+ * single wildcard * value is supported.
+ *
+ * @param value
+ * @param pattern
+ * @return true if the value matches the pattern
+ */
+ public static boolean fuzzyMatch(String value, String pattern) {
+ if (value.equalsIgnoreCase(pattern)) {
+ return true;
+ }
+ if (pattern.contains("*")) {
+ boolean prefixMatches = false;
+ boolean suffixMatches = false;
+
+ int wildcard = pattern.indexOf('*');
+ String prefix = pattern.substring(0, wildcard).toLowerCase();
+ prefixMatches = value.toLowerCase().startsWith(prefix);
+
+ if (pattern.length() > (wildcard + 1)) {
+ String suffix = pattern.substring(wildcard + 1).toLowerCase();
+ suffixMatches = value.toLowerCase().endsWith(suffix);
+ return prefixMatches && suffixMatches;
+ }
+ return prefixMatches || suffixMatches;
+ }
+ return false;
+ }
}