From 81ddeadd4962f110d51a073a270c844407222593 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 14 Oct 2006 00:31:30 +0000 Subject: Replace KCODE checks with String#chars for truncate. Closes #6385 [Manfred Stienstra] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5300 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/text_helper.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_view/helpers/text_helper.rb') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 0e142cbaff..33d86441ef 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -20,13 +20,8 @@ module ActionView # if the +text+ is longer than +length+. def truncate(text, length = 30, truncate_string = "...") if text.nil? then return end - l = length - truncate_string.length - if $KCODE == "NONE" - text.length > length ? text[0...l] + truncate_string : text - else - chars = text.split(//) - chars.length > length ? chars[0...l].join + truncate_string : text - end + l = length - truncate_string.chars.length + text.chars.length > length ? text.chars[0...l] + truncate_string : text end # Highlights the +phrase+ where it is found in the +text+ by surrounding it like -- cgit v1.2.3