Changeset 13597 in josm


Ignore:
Timestamp:
2018-04-04T19:47:35+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16145 - remove white spaces from key/values when pasting tags

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/upload/FixDataHook.java

    r12846 r13597  
    1818import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1919import org.openstreetmap.josm.data.osm.Relation;
    20 import org.openstreetmap.josm.data.osm.Tag;
    2120import org.openstreetmap.josm.gui.MainApplication;
    2221import org.openstreetmap.josm.spi.preferences.Config;
     22import org.openstreetmap.josm.tools.Utils;
    2323
    2424/**
     
    8282            Map<String, String> newKeys = new HashMap<>(keys);
    8383            for (Entry<String, String> e : keys.entrySet()) {
    84                 String v = Tag.removeWhiteSpaces(e.getValue());
    85                 String k = Tag.removeWhiteSpaces(e.getKey());
     84                String v = Utils.removeWhiteSpaces(e.getValue());
     85                String k = Utils.removeWhiteSpaces(e.getKey());
    8686                boolean drop = k.isEmpty() || v.isEmpty();
    8787                if (!e.getKey().equals(k)) {
  • trunk/src/org/openstreetmap/josm/data/osm/Tag.java

    r10737 r13597  
    145145     * @return The string without leading, trailing or multiple inner whitespaces
    146146     * @since 6699
    147      */
     147     * @deprecated since 13597. Use {@link Utils#removeWhiteSpaces(String)} instead
     148     */
     149    @Deprecated
    148150    public static String removeWhiteSpaces(String s) {
    149         if (s == null || s.isEmpty()) {
    150             return s;
    151         }
    152         return Utils.strip(s).replaceAll("\\s+", " ");
     151        return Utils.removeWhiteSpaces(s);
    153152    }
    154153
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r13507 r13597  
    336336                            CheckParameterUtil.ensureThat(val.contains("=>"), "Separate old from new key by '=>'!");
    337337                            final String[] x = val.split("=>", 2);
    338                             check.fixCommands.add(FixCommand.fixChangeKey(Tag.removeWhiteSpaces(x[0]), Tag.removeWhiteSpaces(x[1])));
     338                            check.fixCommands.add(FixCommand.fixChangeKey(Utils.removeWhiteSpaces(x[0]), Utils.removeWhiteSpaces(x[1])));
    339339                        } else if (val != null && "fixDeleteObject".equals(ai.key)) {
    340340                            CheckParameterUtil.ensureThat("this".equals(val), "fixDeleteObject must be followed by 'this'");
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r13584 r13597  
    710710                    commands.add(new ChangePropertyCommand(p, key, null));
    711711                } else if (value.startsWith(" ") || value.endsWith(" ") || value.contains("  ")) {
    712                     commands.add(new ChangePropertyCommand(p, key, Tag.removeWhiteSpaces(value)));
     712                    commands.add(new ChangePropertyCommand(p, key, Utils.removeWhiteSpaces(value)));
    713713                } else if (key.startsWith(" ") || key.endsWith(" ") || key.contains("  ")) {
    714                     commands.add(new ChangePropertyKeyCommand(p, key, Tag.removeWhiteSpaces(key)));
     714                    commands.add(new ChangePropertyKeyCommand(p, key, Utils.removeWhiteSpaces(key)));
    715715                } else {
    716716                    String evalue = Entities.unescape(value);
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolver.java

    r12758 r13597  
    3131import org.openstreetmap.josm.command.Command;
    3232import org.openstreetmap.josm.data.osm.OsmPrimitive;
    33 import org.openstreetmap.josm.data.osm.Tag;
    3433import org.openstreetmap.josm.gui.MainApplication;
    3534import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    3938import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    4039import org.openstreetmap.josm.tools.ImageProvider;
     40import org.openstreetmap.josm.tools.Utils;
    4141
    4242/**
     
    197197        if (primitives == null || primitives.isEmpty())
    198198            return null;
    199         return new ChangePropertyCommand(primitives, Tag.removeWhiteSpaces(tfKey.getText()), Tag.removeWhiteSpaces(tfValue.getText()));
     199        return new ChangePropertyCommand(primitives, Utils.removeWhiteSpaces(tfKey.getText()), Utils.removeWhiteSpaces(tfValue.getText()));
    200200    }
    201201
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r13453 r13597  
    494494        @Override
    495495        public void performTagEdit() {
    496             String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString());
     496            String value = Utils.removeWhiteSpaces(values.getEditor().getItem().toString());
    497497            value = Normalizer.normalize(value, Normalizer.Form.NFC);
    498498            if (value.isEmpty()) {
    499499                value = null; // delete the key
    500500            }
    501             String newkey = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString());
     501            String newkey = Utils.removeWhiteSpaces(keys.getEditor().getItem().toString());
    502502            newkey = Normalizer.normalize(newkey, Normalizer.Form.NFC);
    503503            if (newkey.isEmpty()) {
     
    10601060         */
    10611061        public final void performTagAdding() {
    1062             String key = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString());
    1063             String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString());
     1062            String key = Utils.removeWhiteSpaces(keys.getEditor().getItem().toString());
     1063            String value = Utils.removeWhiteSpaces(values.getEditor().getItem().toString());
    10641064            if (key.isEmpty() || value.isEmpty())
    10651065                return;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java

    r13483 r13597  
    530530            value = "";
    531531        }
    532         value = Tag.removeWhiteSpaces(value);
     532        value = Utils.removeWhiteSpaces(value);
    533533
    534534        // no change if same as before
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Text.java

    r13206 r13597  
    3131import org.openstreetmap.josm.tools.GBC;
    3232import org.openstreetmap.josm.tools.Logging;
     33import org.openstreetmap.josm.tools.Utils;
    3334
    3435/**
     
    207208        }
    208209
    209         v = Tag.removeWhiteSpaces(v);
     210        v = Utils.removeWhiteSpaces(v);
    210211
    211212        if (!"false".equals(use_last_as_default) || auto_increment != null) {
  • trunk/src/org/openstreetmap/josm/tools/TextTagParser.java

    r13544 r13597  
    5959            Matcher m = p.matcher(line);
    6060            if (m.matches()) {
    61                  k = m.group(1).trim();
    62                  v = m.group(2).trim();
     61                 k = Utils.removeWhiteSpaces(m.group(1));
     62                 v = Utils.removeWhiteSpaces(m.group(2));
    6363                 if (unescapeTextInQuotes) {
    6464                     k = unescape(k);
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r13520 r13597  
    823823
    824824    /**
     825     * Removes leading, trailing, and multiple inner whitespaces from the given string, to be used as a key or value.
     826     * @param s The string
     827     * @return The string without leading, trailing or multiple inner whitespaces
     828     * @since 13597
     829     */
     830    public static String removeWhiteSpaces(String s) {
     831        if (s == null || s.isEmpty()) {
     832            return s;
     833        }
     834        return strip(s).replaceAll("\\s+", " ");
     835    }
     836
     837    /**
    825838     * Runs an external command and returns the standard output.
    826839     *
Note: See TracChangeset for help on using the changeset viewer.