Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 23943 - allow negative indices in substring to remove from the end of the string #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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