Skip to content
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

UTF8 strings lowercase conversion #26

Merged
merged 1 commit into from Mar 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/whatlanguage.rb
Expand Up @@ -33,7 +33,7 @@ def languages
def process_text(text)
results = Hash.new(0)
it = 0
text.downcase.split.each do |word|
to_lowercase(text).split.each do |word|
it += 1

languages.each do |lang|
Expand Down Expand Up @@ -62,6 +62,12 @@ def self.filter_from_dictionary(filename)
File.open(filename).each { |word| bf.add(word) }
bf
end

if !defined? UnicodeUtils
define_method(:to_lowercase) { |str| str.downcase }
else
define_method(:to_lowercase) { |str| UnicodeUtils.casefold(str) }
end
end

class String
Expand Down
11 changes: 11 additions & 0 deletions test/test_whatlanguage.rb
@@ -1,6 +1,12 @@
# encoding: utf-8
require "test/unit"

# not a dependency
begin
require 'unicode_utils'
rescue LoadError
end

require 'whatlanguage'

class TestWhatLanguage < Test::Unit::TestCase
Expand Down Expand Up @@ -114,4 +120,9 @@ def test_language_selection_mixed
selective_wl = WhatLanguage.new(:german, :all, :english)
assert_equal :russian, selective_wl.language("Все новости в хронологическом порядке")
end

def test_casing_conversion
skip unless defined? UnicodeUtils
assert_equal "âncora cor âmbar".language, "ÂNCORA COR ÂMBAR".language
end
end