Ignore:
Timestamp:
2017-01-07T00:56:52+01:00 (3 years ago)
Author:
Don-vip
Message:

fix #14199 - JOSM drops empty tags on loading and thus prevents correcting them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r11394 r11435  
    735735
    736736    /**
     737     * Determines if the given String would be empty if stripped.
     738     * This is an efficient alternative to {@code strip(s).isEmpty()} that avoids to create useless String object.
     739     * @param str The string to test
     740     * @return {@code true} if the stripped version of {@code s} would be empty.
     741     * @since 11435
     742     */
     743    public static boolean isStripEmpty(String str) {
     744        if (str != null) {
     745            for (int i = 0; i < str.length(); i++) {
     746                if (!isStrippedChar(str.charAt(i), DEFAULT_STRIP)) {
     747                    return false;
     748                }
     749            }
     750        }
     751        return true;
     752    }
     753
     754    /**
    737755     * An alternative to {@link String#trim()} to effectively remove all leading
    738756     * and trailing white characters, including Unicode ones.
     
    774792        boolean leadingSkipChar = true;
    775793        while (leadingSkipChar && start < end) {
    776             char c = str.charAt(start);
    777             leadingSkipChar = Character.isWhitespace(c) || Character.isSpaceChar(c) || stripChar(skipChars, c);
     794            leadingSkipChar = isStrippedChar(str.charAt(start), skipChars);
    778795            if (leadingSkipChar) {
    779796                start++;
     
    782799        boolean trailingSkipChar = true;
    783800        while (trailingSkipChar && end > start + 1) {
    784             char c = str.charAt(end - 1);
    785             trailingSkipChar = Character.isWhitespace(c) || Character.isSpaceChar(c) || stripChar(skipChars, c);
     801            trailingSkipChar = isStrippedChar(str.charAt(end - 1), skipChars);
    786802            if (trailingSkipChar) {
    787803                end--;
     
    790806
    791807        return str.substring(start, end);
     808    }
     809
     810    private static boolean isStrippedChar(char c, final char ... skipChars) {
     811        return Character.isWhitespace(c) || Character.isSpaceChar(c) || stripChar(skipChars, c);
    792812    }
    793813
Note: See TracChangeset for help on using the changeset viewer.