You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed to strip a leading slash from a URI the other day. I know, really difficult stuff. I assumed we had a method in KiwiUrls to do this simple task, but we only have a method to prepend a leading slash, and a method to strip a trailing slash.
I did the task using some methods in Apache Commons StringUtils and specifically the stripStart method, so StringUtils.stripStart("/some/random/path", "/") returns "some/random/path" as you expect. But, I also combined this with a check for null and blank strings, etc.
So, might as well have a dedicated method in KiwiUrls regardless of how simple it is. It should:
not allow null values (let it throw a NPE like prependLeadingSlash)
allow empty strings, returning empty in this case
trim leading and trailing whitespace, so that " /some/random/path " results in "some/random/path"
return the same value if there is no leading/trailing whitespace and no leading slash
The text was updated successfully, but these errors were encountered:
I needed to strip a leading slash from a URI the other day. I know, really difficult stuff. I assumed we had a method in
KiwiUrls
to do this simple task, but we only have a method to prepend a leading slash, and a method to strip a trailing slash.I did the task using some methods in Apache Commons
StringUtils
and specifically thestripStart
method, soStringUtils.stripStart("/some/random/path", "/")
returns"some/random/path"
as you expect. But, I also combined this with a check for null and blank strings, etc.So, might as well have a dedicated method in
KiwiUrls
regardless of how simple it is. It should:null
values (let it throw a NPE likeprependLeadingSlash
)" /some/random/path "
results in"some/random/path"
The text was updated successfully, but these errors were encountered: