Changeset 15862 in josm
- Timestamp:
- 2020-02-16T15:45:59+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r15760 r15862 90 90 private static final Pattern REMOVE_DIACRITICS = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); 91 91 92 private static final char[]DEFAULT_STRIP ={'\u200B', '\uFEFF'};92 private static final String DEFAULT_STRIP = "\uFEFF\u200B"; 93 93 94 94 private static final String[] SIZE_UNITS = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; … … 781 781 if (str != null) { 782 782 for (int i = 0; i < str.length(); i++) { 783 if (!isStrippedChar(str.charAt(i), DEFAULT_STRIP)) {783 if (!isStrippedChar(str.charAt(i), null)) { 784 784 return false; 785 785 } … … 820 820 return str; 821 821 } 822 return strip(str, stripChars(skipChars));823 }824 825 private static String strip(final String str, final char... skipChars) {826 822 827 823 int start = 0; … … 835 831 } 836 832 boolean trailingSkipChar = true; 837 while (trailingSkipChar && end > start + 1) {833 while (trailingSkipChar && end > start) { 838 834 trailingSkipChar = isStrippedChar(str.charAt(end - 1), skipChars); 839 835 if (trailingSkipChar) { … … 845 841 } 846 842 847 private static boolean isStrippedChar(char c, final char... skipChars) { 848 return Character.isWhitespace(c) || Character.isSpaceChar(c) || stripChar(skipChars, c); 849 } 850 851 private static char[] stripChars(final String skipChars) { 852 if (skipChars == null || skipChars.isEmpty()) { 853 return DEFAULT_STRIP; 854 } 855 856 char[] chars = new char[DEFAULT_STRIP.length + skipChars.length()]; 857 System.arraycopy(DEFAULT_STRIP, 0, chars, 0, DEFAULT_STRIP.length); 858 skipChars.getChars(0, skipChars.length(), chars, DEFAULT_STRIP.length); 859 860 return chars; 861 } 862 863 private static boolean stripChar(final char[] strip, char c) { 864 for (char s : strip) { 865 if (c == s) { 866 return true; 867 } 868 } 869 return false; 843 private static boolean isStrippedChar(char c, final String skipChars) { 844 return Character.isWhitespace(c) || Character.isSpaceChar(c) 845 || DEFAULT_STRIP.indexOf(c) >= 0 846 || (skipChars != null && skipChars.indexOf(c) >= 0); 870 847 } 871 848 -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r15760 r15862 71 71 assertEquals("", Utils.strip(" ")); 72 72 assertEquals("", Utils.strip(someWhite)); 73 assertEquals("", Utils.strip("\u200B")); 74 assertEquals("", Utils.strip("\uFEFF")); 73 75 assertEquals("a", Utils.strip("a")); 74 76 assertEquals("ab", Utils.strip("ab")); … … 85 87 86 88 // extended skip 89 assertNull(Utils.strip(null, "abc")); 90 assertEquals("", Utils.strip("", "b")); 91 assertEquals("", Utils.strip("abbbb", "ab")); 87 92 assertEquals("a", Utils.strip("a", "b")); 93 assertEquals("a", Utils.strip("abbbb", "b")); 88 94 assertEquals("b", Utils.strip("acbcac", "ac")); 89 95 }
Note:
See TracChangeset
for help on using the changeset viewer.