From a6a7a8e1cb9c9b03b42e986bbdd50e501f4b5f4c Mon Sep 17 00:00:00 2001 From: Craig Davey Date: Sat, 12 Jul 2008 20:39:33 -0400 Subject: [PATCH] Added include? to ActiveSupport::Multibyte::Handlers::UTF8Handler so that string.chars.include? acts like string.include? --- .../multibyte/handlers/utf8_handler.rb | 4 ++++ activesupport/test/multibyte_handler_test.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb b/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb index aa9c16f..f609647 100644 --- a/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb +++ b/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb @@ -368,6 +368,10 @@ module ActiveSupport::Multibyte::Handlers #:nodoc: end.join end + def include? (str, sub_str) + str.include?(sub_str) + end + protected # Detect whether the codepoint is in a certain character class. Primarily used by the diff --git a/activesupport/test/multibyte_handler_test.rb b/activesupport/test/multibyte_handler_test.rb index 5575ecc..b0076d0 100644 --- a/activesupport/test/multibyte_handler_test.rb +++ b/activesupport/test/multibyte_handler_test.rb @@ -338,6 +338,15 @@ module UTF8HandlingTest assert_equal [0xfffd].pack('U'), @handler.tidy_bytes("\xef\xbf\xbd") # invalid char end + def test_include? + assert_equal false, @handler.include?("Hello", "A") + assert @handler.include?("Hello", "H") + assert @handler.include?("Καη", "α") + assert @handler.include?("Καη", "αη") + assert @handler.include?("Καη", "Καη") + assert @handler.include?("Καλημέρα κόσμε!", " κόσμε") + end + protected def string_from_classes(classes) -- 1.5.6.1