From 1e1b85270f93b3bca624c99b478f3a9a23be2395 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Sat, 29 Sep 2012 23:40:46 -0400 Subject: [PATCH] Preliminary implementation of server-side forking (issue 137) --- src/com/gitblit/utils/StringUtils.java | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java index e440790..0711338 100644 --- a/src/com/gitblit/utils/StringUtils.java +++ b/src/com/gitblit/utils/StringUtils.java @@ -367,7 +367,7 @@ * @return the first invalid character found or null if string is acceptable */ public static Character findInvalidCharacter(String name) { - char[] validChars = { '/', '.', '_', '-' }; + char[] validChars = { '/', '.', '_', '-', '~' }; for (char c : name.toCharArray()) { if (!Character.isLetterOrDigit(c)) { boolean ok = false; @@ -660,4 +660,31 @@ } return input; } + + /** + * Returns the first path element of a path string. If no path separator is + * found in the path, an empty string is returned. + * + * @param path + * @return the first element in the path + */ + public static String getFirstPathElement(String path) { + if (path.indexOf('/') > -1) { + return path.substring(0, path.indexOf('/')).trim(); + } + return ""; + } + + /** + * Returns the last path element of a path string + * + * @param path + * @return the last element in the path + */ + public static String getLastPathElement(String path) { + if (path.indexOf('/') > -1) { + return path.substring(path.lastIndexOf('/') + 1); + } + return path; + } } \ No newline at end of file -- Gitblit v1.9.1