diff --git a/lib/string_tools/core_ext/string.rb b/lib/string_tools/core_ext/string.rb index 0089422..9b1c956 100644 --- a/lib/string_tools/core_ext/string.rb +++ b/lib/string_tools/core_ext/string.rb @@ -1,3 +1,5 @@ +# coding: utf-8 + require 'rchardet19' require 'addressable/uri' require 'active_support/core_ext/module' @@ -192,6 +194,15 @@ def to_cp1251! self.replace(self.to_cp1251) end + def mb_downcase + # https://github.com/rails/rails/commit/393e19e508a08ede0f5037bccb984e3eb252d579 + if ActiveSupport::VERSION::STRING >= '4.0.0' && ActiveSupport::VERSION::STRING <= '4.2.0' + ActiveSupport::Multibyte::Unicode.send(:database).codepoints + end + + mb_chars.downcase.to_s + end + private def surround_with_ansi(ascii_seq) diff --git a/spec/string_spec.rb b/spec/string_spec.rb new file mode 100644 index 0000000..23d584d --- /dev/null +++ b/spec/string_spec.rb @@ -0,0 +1,9 @@ +# coding: utf-8 + +require 'spec_helper' + +describe String do + describe '#mb_downcase' do + it { expect("Кириллица".mb_downcase).to eq("кириллица") } + end +end