-
-
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
.downcase(Unicode::CaseOptions::Fold) using char ranges #4512
.downcase(Unicode::CaseOptions::Fold) using char ranges #4512
Conversation
d68bbe4
to
10206be
Compare
src/unicode/unicode.cr
Outdated
private def self.check_downcase_fold(char, options) | ||
if options.fold? | ||
result = search_ranges(casefold_ranges, char.ord) | ||
return [char.ord + result] if result |
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.
Use a tuple to avoid a memory allocation:
return {char.ord + result} if result
String.compare will be reworked by another PR |
2f940e5
to
4dcaab3
Compare
Is it GTG? I need these changes to continue Unicode support. Travis build is broken somewhere unrelated to PR. |
@akzhan I'm not sure why this is useful. Where would one use it? Plus, if it's to solve another issue (the one about unicode normalization) I would send a single PR targeting that. Is there any other language where you can downcase and specify to fold case? |
@asterite full Unicode case mapping added in Ruby 2.4 with Take a note that case folding is not usual normalization, see Section 3.13 of the Unicode standard. Also Real case fold comparison doing like: def NFD(text):
return unicodedata.normalize('NFD', text)
def canonical_caseless(text):
return NFD(NFD(text).casefold()) |
|
@akzhan Thank you! I'll review this today or during this week and probably merge it. |
The Fold option is required for correct Unicode string comparison using fold case.
Reimplementation of #4511 using char ranges.
Less memory used.