From cff7ccfc20f775dff4d7f76cb9bf2a7766b071ea Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 11 Apr 2014 13:48:16 -0400
Subject: [PATCH] Build with Java 7
---
src/main/java/com/gitblit/utils/StringUtils.java | 37 ++++++++++++++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/gitblit/utils/StringUtils.java b/src/main/java/com/gitblit/utils/StringUtils.java
index e18bdc4..7605fe0 100644
--- a/src/main/java/com/gitblit/utils/StringUtils.java
+++ b/src/main/java/com/gitblit/utils/StringUtils.java
@@ -127,12 +127,26 @@
retStr.append("%2F");
} else if (inStr.charAt(i) == ' ') {
retStr.append("%20");
+ } else if (inStr.charAt(i) == '&') {
+ retStr.append("%26");
} else {
retStr.append(inStr.charAt(i));
}
i++;
}
return retStr.toString();
+ }
+
+ /**
+ * Flatten the list of strings into a single string with the specified
+ * separator.
+ *
+ * @param values
+ * @param separator
+ * @return flattened list
+ */
+ public static String flattenStrings(String[] values, String separator) {
+ return flattenStrings(Arrays.asList(values), separator);
}
/**
@@ -293,7 +307,7 @@
* @param bytes
* @return byte array as hex string
*/
- private static String toHex(byte[] bytes) {
+ public static String toHex(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
if ((bytes[i] & 0xff) < 0x10) {
@@ -747,4 +761,25 @@
}
return input.replace('\n',' ').replace('\r', ' ').trim();
}
+
+
+ /**
+ * Encode the username for user in an url.
+ *
+ * @param name
+ * @return the encoded name
+ */
+ public static String encodeUsername(String name) {
+ return name.replace("@", "%40").replace(" ", "%20").replace("\\", "%5C");
+ }
+
+ /**
+ * Decode a username from an encoded url.
+ *
+ * @param name
+ * @return the decoded name
+ */
+ public static String decodeUsername(String name) {
+ return name.replace("%40", "@").replace("%20", " ").replace("%5C", "\\");
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1