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

Please add ltrim and rtrim to String #5589

Closed
DartBot opened this issue Oct 1, 2012 · 9 comments
Closed

Please add ltrim and rtrim to String #5589

DartBot opened this issue Oct 1, 2012 · 9 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Oct 1, 2012

This issue was originally filed by jjinux...@google.com


The String class has a trim method that trims both sides, but there's no method to trim just the left side or just the right side. Sometimes you need those, and they're really easy to implement using some code like this:

main() {
  var start = " foo ";
  var end = " foo ";
  start = start.replaceFirst(new RegExp(r"^\s+"), ""); // ltrim
  end = end.replaceFirst(new RegExp(r"\s+$"), ""); // rtrim
  print("<$start>");
  print("<$end>");
}

Dart Editor:
Version 0.1.0.201210010959, build 13075
Dart SDK version 13075

@lrhn
Copy link
Member

lrhn commented Oct 1, 2012

Yes, it should be there.


Added this to the M2 milestone.
Added Accepted label.

@floitschG
Copy link
Contributor

Removed this from the M2 milestone.
Added this to the M3 milestone.

@anders-sandholm
Copy link
Contributor

Removed this from the M3 milestone.
Added this to the M4 milestone.

@floitschG
Copy link
Contributor

Removed this from the M4 milestone.
Added this to the M5 milestone.
Added Ready-to-implement label.

@kevmoo
Copy link
Member

kevmoo commented Dec 2, 2013

Would we want named args for trim?

trim({bool trimLeft: true, bool trimRight: true})

To avoid member bloat?


Removed this from the M5 milestone.
Added PatchesWelcome label.

@lrhn
Copy link
Member

lrhn commented Dec 2, 2013

I think I'd prefer separate methods.
Writing "s.trim(trimRight: false)" just doesn't read very well to me.

For names, I would prefer "trimLeft"/"trimRight". It's not as readable as "leftTrim"/"rightTrim", but not a lot worse, and it's much more discoverable. It'll be right next to "trim" in the API documentation.
 

@floitschG
Copy link
Contributor

Agree with Lasse.

@lrhn
Copy link
Member

lrhn commented Mar 12, 2014

Set owner to @lrhn.
Added Started label.

@lrhn
Copy link
Member

lrhn commented Mar 14, 2014

Added Fixed label.

@DartBot DartBot added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Mar 14, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants