Skip to content

Commit

Permalink
Fix Unicode.letter? to include all letter categories
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Nov 18, 2021
1 parent c722e85 commit 511ab8e
Show file tree
Hide file tree
Showing 5 changed files with 568 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/generate_unicode_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ alternate_ranges = alternate_ranges(downcase_one_ranges)
casefold_ranges = case_ranges entries, &.casefold

all_strides = {} of String => Array(Stride)
categories = %w(Lu Ll Lt Mn Mc Me Nd Nl No Zs Zl Zp Cc Cf Cs Co Cn)
categories = %w(Lu Ll Lt Lm Lo Mn Mc Me Nd Nl No Zs Zl Zp Cc Cf Cs Co Cn)

categories.each do |category|
all_strides[category] = strides entries, category, &.general_category
Expand Down
16 changes: 16 additions & 0 deletions spec/std/char_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ describe "Char" do
it { ' '.ascii_letter?.should be_false }
end

it "#letter?" do
'A'.letter?.should be_true # Unicode General Category Lu
'a'.letter?.should be_true # Unicode General Category Ll
'Dž'.letter?.should be_true # Unicode General Category Lt
'ʰ'.letter?.should be_true # Unicode General Category Lm
'か'.letter?.should be_true # Unicode General Category Lo

'ः'.letter?.should be_false # M
'1'.letter?.should be_false # Nd
'Ⅰ'.letter?.should be_false # Nl
'_'.letter?.should be_false # P
'$'.letter?.should be_false # S
' '.letter?.should be_false # Z
'\n'.letter?.should be_false # C
end

describe "alphanumeric?" do
it { 'a'.alphanumeric?.should be_true }
it { 'A'.alphanumeric?.should be_true }
Expand Down
3 changes: 3 additions & 0 deletions src/char.cr
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ struct Char

# Returns `true` if this char is a letter.
#
# All codepoints in the Unicode General Category `L` (Letter) are considered
# a letter.
#
# ```
# 'c'.letter? # => true
# 'á'.letter? # => true
Expand Down
Loading

0 comments on commit 511ab8e

Please sign in to comment.