Changeset 6699 in josm


Ignore:
Timestamp:
2014-01-16T02:42:49+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9547 - Remove multiple whitespaces inside values

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

Legend:

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

    r6084 r6699  
    1919import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2020import org.openstreetmap.josm.data.osm.Relation;
     21import org.openstreetmap.josm.data.osm.Tag;
    2122
    2223/**
     
    7677            Map<String, String> newKeys = new HashMap<String, String>(keys);
    7778            for (Entry<String, String> e : keys.entrySet()) {
    78                 String v = e.getValue().trim();
    79                 String k = e.getKey().trim();
     79                String v = Tag.removeWhiteSpaces(e.getValue());
     80                String k = Tag.removeWhiteSpaces(e.getKey());
    8081                if(!e.getKey().equals(k)) {
    8182                    boolean drop = k.isEmpty() || v.isEmpty();
  • trunk/src/org/openstreetmap/josm/data/osm/Tag.java

    r6513 r6699  
    33
    44import org.openstreetmap.josm.tools.CheckParameterUtil;
     5import org.openstreetmap.josm.tools.Utils;
    56
    67/**
     
    1718     * Create an empty tag whose key and value are empty.
    1819     */
    19     public Tag(){
     20    public Tag() {
    2021        this("", "");
    2122    }
     
    119120        return key + "=" + value;
    120121    }
     122
     123    /**
     124     * Removes leading, trailing, and multiple inner whitespaces from the given string, to be used as a key or value.
     125     * @param s The string
     126     * @return The string without leading, trailing or multiple inner whitespaces
     127     * @since 6699
     128     */
     129    public static String removeWhiteSpaces(String s) {
     130        if (s == null || s.isEmpty()) {
     131            return s;
     132        }
     133        return Utils.strip(s).replaceAll("\\s+", " ");
     134    }
    121135}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r6681 r6699  
    142142                        CheckParameterUtil.ensureThat(val.contains("=>"), "Separate old from new key by '=>'!");
    143143                        final String[] x = val.split("=>", 2);
    144                         check.keyChange.put(x[0].trim(), x[1].trim());
     144                        check.keyChange.put(Tag.removeWhiteSpaces(x[0]), Tag.removeWhiteSpaces(x[1]));
    145145                    } else if ("suggestAlternative".equals(ai.key) && val != null) {
    146146                        check.alternatives.add(val);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6650 r6699  
    3636import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3737import org.openstreetmap.josm.data.osm.OsmUtils;
     38import org.openstreetmap.josm.data.osm.Tag;
    3839import org.openstreetmap.josm.data.validation.Severity;
    3940import org.openstreetmap.josm.data.validation.Test;
     
    563564                    commands.add(new ChangePropertyCommand(p, key, null));
    564565                } else if (value.startsWith(" ") || value.endsWith(" ")) {
    565                     commands.add(new ChangePropertyCommand(p, key, value.trim()));
     566                    commands.add(new ChangePropertyCommand(p, key, Tag.removeWhiteSpaces(value)));
    566567                } else if (key.startsWith(" ") || key.endsWith(" ")) {
    567                     commands.add(new ChangePropertyKeyCommand(p, key, key.trim()));
     568                    commands.add(new ChangePropertyKeyCommand(p, key, Tag.removeWhiteSpaces(key)));
    568569                } else {
    569570                    String evalue = entities.unescape(value);
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolver.java

    r6616 r6699  
    3232import org.openstreetmap.josm.command.Command;
    3333import org.openstreetmap.josm.data.osm.OsmPrimitive;
     34import org.openstreetmap.josm.data.osm.Tag;
    3435import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    3536import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     
    189190        if (primitives == null || primitives.isEmpty())
    190191            return null;
    191         return new ChangePropertyCommand(primitives, tfKey.getText(), tfValue.getText());
     192        return new ChangePropertyCommand(primitives, Tag.removeWhiteSpaces(tfKey.getText()), Tag.removeWhiteSpaces(tfValue.getText()));
    192193    }
    193194
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r6546 r6699  
    331331         */
    332332        private void performTagEdit() {
    333             String value = values.getEditor().getItem().toString().trim();
     333            String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString());
    334334            // is not Java 1.5
    335335            //value = java.text.Normalizer.normalize(value, java.text.Normalizer.Form.NFC);
     
    337337                value = null; // delete the key
    338338            }
    339             String newkey = keys.getEditor().getItem().toString().trim();
     339            String newkey = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString());
    340340            //newkey = java.text.Normalizer.normalize(newkey, java.text.Normalizer.Form.NFC);
    341341            if (newkey.isEmpty()) {
     
    732732         */
    733733        public void performTagAdding() {
    734             String key = keys.getEditor().getItem().toString().trim();
    735             String value = values.getEditor().getItem().toString().trim();
     734            String key = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString());
     735            String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString());
    736736            if (key.isEmpty() || value.isEmpty()) return;
    737737            lastAddKey = key;
     
    743743        }
    744744       
    745        
    746745        public void undoAllTagsAdding() {
    747746            Main.main.undoRedo.undo(commandCount);
    748747        }
    749 
    750748
    751749        private void disableTagIfNeeded(final Tag t, final JosmAction action) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r6572 r6699  
    714714            }
    715715           
    716             v = v.trim();
     716            v = Tag.removeWhiteSpaces(v);
    717717
    718718            if (!"false".equals(use_last_as_default) || auto_increment != null) {
     
    10761076                value = "";
    10771077            }
    1078             value = value.trim();
     1078            value = Tag.removeWhiteSpaces(value);
    10791079
    10801080            // no change if same as before
Note: See TracChangeset for help on using the changeset viewer.