diff options
author | Andrey Loskutov <loskutov@gmx.de> | 2016-09-14 09:29:20 +0200 |
---|---|---|
committer | Andrey Loskutov <loskutov@gmx.de> | 2016-09-14 07:43:52 -0400 |
commit | 619329c84e41f9abe83616795d65af8c7fed5f3d (patch) | |
tree | 2d51137446b7d1950e6e2e008018d751e6a2c251 /org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal | |
parent | 57a263f1823d164142235a72072154f0568cb61c (diff) | |
download | jgit-619329c84e41f9abe83616795d65af8c7fed5f3d.tar.gz jgit-619329c84e41f9abe83616795d65af8c7fed5f3d.zip |
Ignore trailing spaces in directory rule patterns
Bug: 500967
Change-Id: I7fabc2654af97011c62f46d5c30ee992341e45e2
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java index e354c7114c..70c5199030 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java @@ -76,10 +76,50 @@ public class Strings { * @return new string with all trailing characters removed */ public static String stripTrailing(String pattern, char c) { - while (pattern.length() > 0 - && pattern.charAt(pattern.length() - 1) == c) - pattern = pattern.substring(0, pattern.length() - 1); - return pattern; + for (int i = pattern.length() - 1; i >= 0; i--) { + char charAt = pattern.charAt(i); + if (charAt != c) { + if (i == pattern.length() - 1) { + return pattern; + } + return pattern.substring(0, i + 1); + } + } + return ""; //$NON-NLS-1$ + } + + /** + * @param pattern + * non null + * @return new string with all trailing whitespace removed + */ + public static String stripTrailingWhitespace(String pattern) { + for (int i = pattern.length() - 1; i >= 0; i--) { + char charAt = pattern.charAt(i); + if (!Character.isWhitespace(charAt)) { + if (i == pattern.length() - 1) { + return pattern; + } + return pattern.substring(0, i + 1); + } + } + return ""; //$NON-NLS-1$ + } + + /** + * @param pattern + * non null + * @return true if the last character, which is not whitespace, is a path + * separator + */ + public static boolean isDirectoryPattern(String pattern) { + for (int i = pattern.length() - 1; i >= 0; i--) { + char charAt = pattern.charAt(i); + if (!Character.isWhitespace(charAt)) { + return charAt == FastIgnoreRule.PATH_SEPARATOR; + } + } + return false; } static int count(String s, char c, boolean ignoreFirstLast) { |