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
strings: document that order of pairs matters in NewReplacer #32699
Comments
I think this is clear. Maybe
But maybe that's obvious 🤔 |
Thanks for your insight. I find a little confusing that the first "leftmost" is relative to the target string while the second is relative to the order of the arguments, so maybe we should get rid of the latter:
But I'm not sure how integrate the "non overlapping" part. Here's another try:
|
@pam4 I like this one! How about this? Sounds maybe a little simpler to me
But I feel like we could go on forever 😄 Maybe it's time to submit a CL? Do you want to do it or should I go ahead? |
@rentziass, your wording sounds fine to me. Please go ahead with the CL if you are willing. Thanks! |
Change https://golang.org/cl/185099 mentions this issue: |
The current documentation doesn't specify the result of the following code (could be either "declare" or "decodel") because they both match at the same starting position:
The actual result is "declare", i.e. the first pair takes precedence (not the longest
old
string).I just run into a use case that would require this precedence to be guaranteed, but I can't rely on it because it's not documented.
Looking at the code I presume the precedence is intentional: the generic algorithm uses a lookup trie for prioritized key/value pairs, and keys are added with decreasing priority, see here (
len(oldnew)-i
is the priority).Unless there is actually a reason for it to be left undefined, I propose something like:
Ok, hopefully someone will come up with better words...
The text was updated successfully, but these errors were encountered: