Skip to content

Commit

Permalink
fix #23943 - patch by Famlam - allow negative values for substring to…
Browse files Browse the repository at this point in the history
… count from the end of the string

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19259 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
stoecker committed Nov 15, 2024
1 parent 970825b commit eeb513e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1034,12 +1034,12 @@ public static String substring(String s, /* due to missing Cascade.convertTo for
* and ending at index {@code end}, (exclusive, 0-indexed).
* @param s The base string
* @param begin The start index
* @param end The end index
* @param end The end index. If negative, it counts from the end of the string
* @return the substring
* @see String#substring(int, int)
*/
public static String substring(String s, float begin, float end) {
return s == null ? null : s.substring((int) begin, (int) end);
return s == null ? null : s.substring((int) begin, (int) (end >= 0 ? end : s.length() + end));
}

/**
Expand Down

0 comments on commit eeb513e

Please sign in to comment.