To complement sys::Uri.plusSlash what do you think of Uri.removeSlash?
sys::Uri.plusSlash
Uri.removeSlash
I find myself doing this over and over again. And...
if (uri.toStr.endsWith("/")) uri = `${uri.toStr[0..<-1]}`
...just isn't that elegant!
EDIT: The above code may be simplified to:
if (uri.isDir) url = url.parent.plusName(url.name)
which isn't so bad.
Actually that seems unusual to me - wouldn't you typically use parent in that context? When would you want to get a directory URI as a file URI?
parent
Looking back through my code for examples and context, I think you're right - I was a little trigger happy with the suggestion.
There are generally 2 scenarios when I want to remove a slash, and neither really warrant the extra method:
`/wot/` + `/ever` --> `/ever`
when what I really want is:
`/wot/` + `ever` --> `/wot/ever`
Wisp's modBase and modRel is a good example of this, as modRel always starts with a / (contrary to the docs at web::WebReq.modBase).
modBase
modRel
/
web::WebReq.modBase
Login or Signup to reply.
SlimerDude Mon 16 Sep 2013
To complement
sys::Uri.plusSlash
what do you think ofUri.removeSlash
?I find myself doing this over and over again. And...
...just isn't that elegant!
EDIT: The above code may be simplified to:
which isn't so bad.
brian Mon 16 Sep 2013
Actually that seems unusual to me - wouldn't you typically use
parent
in that context? When would you want to get a directory URI as a file URI?SlimerDude Mon 16 Sep 2013
Looking back through my code for examples and context, I think you're right - I was a little trigger happy with the suggestion.
There are generally 2 scenarios when I want to remove a slash, and neither really warrant the extra method:
when what I really want is:
Wisp's
modBase
andmodRel
is a good example of this, asmodRel
always starts with a/
(contrary to the docs atweb::WebReq.modBase
).