Changeset 19261 in josm for trunk/src


Ignore:
Timestamp:
2024-11-25T23:08:52+01:00 (2 weeks ago)
Author:
taylor.smock
Message:

See #24014: Add multiline and normalize attributes to preset xsd

normalize="false" will prevent all whitespace normalization while
normalize="true" + multiline="true" will strip start and end whitespace and
inner whitespace that is not newlines.

The primary reason for this change is osmwiki:Key:inscription which can have
newlines in order to match the inscription.

This does not modify UI elements to support multiline editing.

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Text.java

    r18801 r19261  
    1414import java.util.Collections;
    1515import java.util.List;
     16import java.util.regex.Pattern;
    1617
    1718import javax.swing.AbstractButton;
     
    4849 */
    4950public class Text extends KeyedItem {
     51    private static final Pattern MULTILINE_WHITESPACE_PATTERN = Pattern.compile("[\\s&&[^\n]]+");
    5052
    5153    private static int auto_increment_selected; // NOSONAR
     
    241243        }
    242244
    243         v = Utils.removeWhiteSpaces(v);
     245        if (this.normalize) {
     246            if (this.multiline) {
     247                v = Utils.removeWhiteSpaces(MULTILINE_WHITESPACE_PATTERN, v);
     248            } else {
     249                v = Utils.removeWhiteSpaces(v);
     250            }
     251        }
    244252
    245253        if (!"false".equals(use_last_as_default) || auto_increment != null) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/TextItem.java

    r17608 r19261  
    2323    /** The context used for translating {@link #text} */
    2424    public String text_context; // NOSONAR
     25
     26    /** {@code true} if the value is a multiline value */
     27    public boolean multiline; // NOSONAR
     28    /** {@code true} if the value should be normalized */
     29    public boolean normalize = true; // NOSONAR
    2530
    2631    /** The localized version of {@link #text} */
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r19133 r19261  
    821821     */
    822822    public static String removeWhiteSpaces(String s) {
     823        return removeWhiteSpaces(WHITE_SPACES_PATTERN, s);
     824    }
     825
     826    /**
     827     * Removes leading, trailing, and multiple inner whitespaces from the given string, to be used as a key or value.
     828     * @param s The string
     829     * @param whitespaces The regex for whitespaces to remove outside the leading and trailing whitespaces (see {@link #strip(String)})
     830     * @return The string without leading, trailing or multiple inner whitespaces
     831     * @since 19261
     832     */
     833    public static String removeWhiteSpaces(Pattern whitespaces, String s) {
    823834        if (isEmpty(s)) {
    824835            return s;
    825836        }
    826         return strip(s).replaceAll("\\s+", " ");
     837        return whitespaces.matcher(strip(s)).replaceAll(" ");
    827838    }
    828839
Note: See TracChangeset for help on using the changeset viewer.