Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ab61b8908ce4
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eab00944a975
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 22, 2016

  1. Fixed String#upcase and String#downcase optimization. Fixes #3566

    Ary Borenszweig committed Nov 22, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    nomadium Miguel Landaeta
    Copy the full SHA
    197ba00 View commit details
  2. Allow passing case options to String#capitalize

    Ary Borenszweig committed Nov 22, 2016
    2

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    nomadium Miguel Landaeta
    Copy the full SHA
    eab0094 View commit details
Showing with 8 additions and 6 deletions.
  1. +2 −0 spec/std/string_spec.cr
  2. +6 −6 src/string.cr
2 changes: 2 additions & 0 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
@@ -470,6 +470,7 @@ describe "String" do
assert { "áéíóúā".upcase.should eq("ÁÉÍÓÚĀ") }
assert { "aeıiou".upcase(Unicode::CaseOptions::Turkic).should eq("AEIİOU") }
assert { "áeíoú".upcase(Unicode::CaseOptions::ASCII).should eq("áEíOú") }
assert { "aeiou".upcase(Unicode::CaseOptions::Turkic).should eq("AEİOU") }
assert { "baffle".upcase.should eq("BAFFLE") }
assert { "".upcase.should eq("FF") }
end
@@ -479,6 +480,7 @@ describe "String" do
assert { "HELLO MAN!".capitalize.should eq("Hello man!") }
assert { "".capitalize.should eq("") }
assert { "fflİ".capitalize.should eq("FFLi̇") }
assert { "iO".capitalize(Unicode::CaseOptions::Turkic).should eq("İo") }
end

describe "chomp" do
12 changes: 6 additions & 6 deletions src/string.cr
Original file line number Diff line number Diff line change
@@ -877,7 +877,7 @@ class String
def downcase(options = Unicode::CaseOptions::None)
return self if empty?

if ascii_only?
if ascii_only? && ((options == Unicode::CaseOptions::None) || options.ascii?)
String.new(bytesize) do |buffer|
bytesize.times do |i|
buffer[i] = to_unsafe[i].unsafe_chr.downcase.ord.to_u8
@@ -904,7 +904,7 @@ class String
def upcase(options = Unicode::CaseOptions::None)
return self if empty?

if ascii_only?
if ascii_only? && ((options == Unicode::CaseOptions::None) || options.ascii?)
String.new(bytesize) do |buffer|
bytesize.times do |i|
buffer[i] = to_unsafe[i].unsafe_chr.upcase.ord.to_u8
@@ -928,10 +928,10 @@ class String
# ```
# "hEllO".capitalize # => "Hello"
# ```
def capitalize
def capitalize(options = Unicode::CaseOptions::None)
return self if empty?

if ascii_only?
if ascii_only? && ((options == Unicode::CaseOptions::None) || options.ascii?)
String.new(bytesize) do |buffer|
bytesize.times do |i|
if i == 0
@@ -946,9 +946,9 @@ class String
String.build(bytesize) do |io|
each_char_with_index do |char, i|
if i == 0
char.upcase { |c| io << c }
char.upcase(options) { |c| io << c }
else
char.downcase { |c| io << c }
char.downcase(options) { |c| io << c }
end
end
end