-
Notifications
You must be signed in to change notification settings - Fork 471
Belt.String #3467
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
Belt.String #3467
Conversation
Add some functions to Belt.String
687f92d
to
e74cd69
Compare
Before merging it, it would be helpful if we have a second eye to have a look if everything is okay. |
@bsansouci @phated : I'm pinging as you were active lately on the original PR, how does that look to you? Benjamin: how would you feel about this on the native side? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me (beside the substr thing)
substr "abcdefghij" ~from: 12 ~len: 2= "" | ||
]} | ||
*) | ||
external substr : t -> from:int -> len:int -> t = "substr" [@@bs.send] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO substr
should be replaced by substring
as it's not recommended to use it, see below
Warning: Although String.prototype.substr(…) is not strictly deprecated (as in "removed from the Web standards"), it is considered a legacy function and should be avoided when possible. It is not part of the core JavaScript language and may be removed in the future. If at all possible, use the substring() method instead.
(source https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given String.prototype.substring
is equivalent to String.prototype.slice
(index
+ endIndex
) and String.prototype.substr
is index
+ length
, I figured it would be interesting to leave the two ways of doing so.
if the substr
signature isn't really interesting for users (I'm not sure if widely used), we can remove it altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah considering the fact that substring≃slice, feel free to forget what I said :)
Nice read about diff between substring & slice https://stackoverflow.com/questions/2243824/what-is-the-difference-between-string-slice-and-string-substring#2243835
substrToEnd "abcdefghij" ~from: 12 = "" | ||
]} | ||
*) | ||
external substrToEnd : t -> from:int -> t = "substr" [@@bs.send] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to go for substring, I guess we should use substringToEnd here
Hold on; are we doing the substring type thing or not? Like Rust/Go/Swift |
@chenglou what do you mean? |
We were discussing about having a substring type. This is needed for native also, since native's string representation is much more naive. Substring is probably the best tradeoff we can make in terms of interop, perf, correctness (unicode) and UX: https://developer.apple.com/documentation/swift/substring Though us talking about it has slowed down the progress to Belt.String api, which is unfortunate |
(Discussed offline. @bloodyowl is looking into this |
what's the status of this? I'd love to have |
@bobzhang rebased against master so it might be easier to PR to master instead of #2758.