Changes between Initial Version and Version 1 of Ticket #23943


Ignore:
Timestamp:
2024-09-29T19:58:50+02:00 (12 months ago)
Author:
Famlam
Comment:

Patch here: https://github.com/JOSM/josm/pull/143

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #23943

    • Property Summary Mapcss "substring" function: allow negative end index to remove from the end[PATCH] Mapcss "substring" function: allow negative end index to remove from the end
  • Ticket #23943 – Description

    initial v1  
    1919A much nicer solution would be to permit negative end indices in the `substring(str, start, end)` function, which should mean to count the final index from the length of the string, e.g.: `substring("foo bar baz", 1, -1)` would return `oo bar ba`. This is especially useful for variable-length strings in mapcss.
    2020
    21 I'm not familiar enough with Java to dare to make it a patch, but I can image the new function to look something like:
     21A possible patch:
    2222{{{#!java
    2323public static String substring(String s, float begin, float end) {
    24   return s == null ? null : s.substring((int) begin, (int) (end > 0 ? end : s.length() + end));
     24  return s == null ? null : s.substring((int) begin, (int) (end >= 0 ? end : s.length() + end));
    2525}
    2626}}}