Changeset 5699 in josm
- Timestamp:
- 2013-02-07T18:57:30+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
r5206 r5699 11 11 import java.util.Arrays; 12 12 import java.util.List; 13 import java.util.regex.Matcher; 14 import java.util.regex.Pattern; 13 15 14 16 import org.openstreetmap.josm.Main; … … 107 109 } 108 110 111 public static Object get(List objects, float index) { 112 int idx = Math.round(index); 113 if (idx >=0 && idx < objects.size()) 114 return objects.get(idx); 115 return null; 116 } 117 118 public List split(String sep, String toSplit) { 119 return Arrays.asList(toSplit.split(Pattern.quote(sep))); 120 } 121 109 122 public Color rgb(float r, float g, float b) { 110 123 Color c = null; … … 229 242 public int length(String s) { 230 243 return s.length(); 244 } 245 246 public int length(List l) { 247 return l.size(); 231 248 } 232 249 … … 263 280 Color res = Main.pref.getColor(s, null); 264 281 return res != null ? res : def; 282 } 283 284 public static boolean regexp_test(String pattern, String target) { 285 return Pattern.matches(pattern, target); 286 } 287 288 public static boolean regexp_test(String pattern, String target, String flags) { 289 int f = 0; 290 if (flags.contains("i")) { 291 f |= Pattern.CASE_INSENSITIVE; 292 } 293 if (flags.contains("s")) { 294 f |= Pattern.DOTALL; 295 } 296 if (flags.contains("m")) { 297 f |= Pattern.MULTILINE; 298 } 299 return Pattern.compile(pattern, f).matcher(target).matches(); 300 } 301 302 public static List regexp_match(String pattern, String target, String flags) { 303 int f = 0; 304 if (flags.contains("i")) { 305 f |= Pattern.CASE_INSENSITIVE; 306 } 307 if (flags.contains("s")) { 308 f |= Pattern.DOTALL; 309 } 310 if (flags.contains("m")) { 311 f |= Pattern.MULTILINE; 312 } 313 Matcher m = Pattern.compile(pattern, f).matcher(target); 314 if (m.matches()) { 315 List result = new ArrayList(m.groupCount()); 316 for (int i=1; i<=m.groupCount(); i++) { 317 result.add(m.group(i)); 318 } 319 return result; 320 } else 321 return null; 322 } 323 324 public static List regexp_match(String pattern, String target) { 325 Matcher m = Pattern.compile(pattern).matcher(target); 326 if (m.matches()) { 327 List result = new ArrayList(m.groupCount()); 328 for (int i=1; i<=m.groupCount(); i++) { 329 result.add(m.group(i)); 330 } 331 return result; 332 } else 333 return null; 334 } 335 336 public long osm_id() { 337 return env.osm.getUniqueId(); 265 338 } 266 339 }
Note:
See TracChangeset
for help on using the changeset viewer.