From 9b72a2e674f7cbc320b0b72fc71ad813d296ab12 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 22 Sep 2011 12:04:43 -0400
Subject: [PATCH] Updated to JGit 1.1.0 and reverse-sort library dependencies.
---
src/com/gitblit/utils/StringUtils.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java
index bb1928a..77d3cbb 100644
--- a/src/com/gitblit/utils/StringUtils.java
+++ b/src/com/gitblit/utils/StringUtils.java
@@ -342,4 +342,57 @@
}
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;
+ }
}
--
Gitblit v1.9.1