-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add a TrimmedString.trim method #487
Conversation
This is somewhat similar to `FiniteStringOps.truncate` in that it's guaranteed to turn any `String` into a `TrimmedString`. There are some funny characters that get removed by `String.trim` but don't match on `\s` in regular expressions. I've added an example to demonstrate that these characters can lead to a `String` being "trimmed" a bit more than would technically be necessary to match the `TrimmedString` regex.
Oops I have a broken test :( |
Strings are hard. I'm not sure what to do here. |
So the culprit is |
So |
This should now match up with the strings that `String.trim` produces. I had to change `.*` to `(?s:.*)` because the line separator character isn't removed by `trim` yet doesn't match `.*` without the `s` flag, so a string like `"\u2028"` can be the result of `trim` but didn't previously match the regular expression. Scalastyle and scalafmt had some competing opinions on how I should format this long regex Witness expression.
Okay I've upgraded to a |
I'm not sure what the build failure is about. Any ideas? Also locally I have a change to add a scalacheck generator for trimmed strings -- should I add that here or would you prefer that as a separate PR afterwards? |
The test passes on the JVM but fails with JS. Oh no. :-( This is not the first time that we have difficulties writing regexes that should work on the JVM and with JS (see #453 (comment) and #357 (comment)). I've no idea if the current regex can be changed to work on both platforms. I'm at a point where I would suggest adding a I'm sorry this is not a straightforward change as it should have been. |
Instead of adding WRT the ScalaCheck instances I'm fine with both. |
Thanks again for the guidance @fthomas! I'm inclined to agree with your suggestion of adding a |
This also adds `TrimmedString.trim` and is a replacement for fthomas#487 based on the discussion there.
This is somewhat similar to
FiniteStringOps.truncate
in that it'sguaranteed to turn any
String
into aTrimmedString
.There are some funny characters that get removed by
String.trim
butdon't match on
\s
in regular expressions. I've added an example todemonstrate that these characters can lead to a
String
being "trimmed"a bit more than would technically be necessary to match the
TrimmedString
regex.