-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix: String#gsub replacing ascii chars to work in non-ascii string #5350
Conversation
UPDATED: I've implemented the better solution. |
This would do as a proper solution in if my_char == char
buffer[i] = replacement.ord.to_u8
else
(buffer + i).copy_from(to_unsafe + i, my_char.bytesize)
end |
solution is to use |
There is no |
Can I get a review? It should be a good solution now, not just a workaround as initially announced. |
src/string.cr
Outdated
each_char_with_index do |my_char, i| | ||
buffer[i] = if my_char == char | ||
to_slice.each_with_index do |byte, i| | ||
buffer[i] = if char === byte |
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.
Please don't use ===
, use char.ord == byte
.
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.
Also i'd much prefer
if char.ord == byte
buffer[i] = replacement.ord.to_u8
else
buffer[i] = byte
end
to avoid the ugly indent.
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.
@RX14 I vote to change formatter rule for this indent to uniformly used 2 spaces.
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.
That's another issue, and I disagree with you.
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.
Out of the curiosity, how's that you don't want to change the rule, while in the same time you suggest against using it? Is there sth I don't get?
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.
Because changing the rule would mean it looks like
buffer[i] = if char.ord == byte
replacement.ord.to_u8
else
byte
end
which i think is even more ugly than indenting it all.
My preference goes:
- what I suggested (assign in the if)
- what's implemented in this PR (indent the if)
- what you suggested (don't indent the if)
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.
Got it! for my taste it'd be 3,1,2 - in that order.
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.
- is what it currently looks like. Until now this PR doesn't change anything about that.
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.
well it won't get changed if it's not in this PR
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.
@RX14 now it is =)
|
This PR needs to be rebased onto master to pick up the latest travis.yml changes to pass CI. |
02ab638
to
89bf14c
Compare
Rebased. |
@bcardiff this should also probably be cherry-picked into 0.24.2 but i've milestoned it |
Fixes #5348