Changeset 6805 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-02-03T18:07:45+01:00 (10 years ago)
Author:
bastiK
Message:

fixed #9674 - Support for escaping special characters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r6749 r6805  
    55
    66import java.awt.Color;
     7import java.io.UnsupportedEncodingException;
    78import java.lang.annotation.ElementType;
    89import java.lang.annotation.Retention;
     
    1213import java.lang.reflect.InvocationTargetException;
    1314import java.lang.reflect.Method;
     15import java.net.URLEncoder;
    1416import java.util.ArrayList;
    1517import java.util.Arrays;
     
    524526            return s == null ? null : s.replace(target, replacement);
    525527        }
     528
     529        /**
     530         * Percent-encode a string. (See https://en.wikipedia.org/wiki/Percent-encoding)
     531         * This is especially useful for data urls, e.g.
     532         * <code>icon-image: concat("data:image/svg+xml,", URL_encode("<svg>...</svg>"));</code>
     533         * @param s arbitrary string
     534         * @return the encoded string
     535         */
     536        public static String URL_encode(String s) {
     537            try {
     538                return s == null ? null : URLEncoder.encode(s, "UTF-8");
     539            } catch (UnsupportedEncodingException ex) {
     540                throw new RuntimeException();
     541            }
     542        }
    526543    }
    527544
Note: See TracChangeset for help on using the changeset viewer.