From 080c2884c9c6212a2f087b94edf0ddaa41d7a171 Mon Sep 17 00:00:00 2001 From: William Morgan Date: Mon, 15 Jun 2009 08:00:07 -0700 Subject: [PATCH] make multibyte display "work" for non-utf8 locales A nasty hack, but fixes a previous utf8-centric change. --- lib/sup.rb | 2 +- lib/sup/util.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/sup.rb b/lib/sup.rb index 96510b2..7444df0 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -243,7 +243,7 @@ end Redwood::log "using character set encoding #{$encoding.inspect}" else Redwood::log "warning: can't find character set by using locale, defaulting to utf-8" - $encoding = "utf-8" + $encoding = "UTF-8" end ## now everything else (which can feel free to call Redwood::log at load time) diff --git a/lib/sup/util.rb b/lib/sup/util.rb index 8a3004f..ece52ba 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -172,7 +172,15 @@ class Object end class String - def display_length; scan(/./u).size end + ## nasty multibyte hack for ruby 1.8. if it's utf-8, split into chars using + ## the utf8 regex and count those. otherwise, use the byte length. + def display_length + if $encoding == "UTF-8" + scan(/./u).size + else + size + end + end def camel_to_hyphy self.gsub(/([a-z])([A-Z0-9])/, '\1-\2').downcase -- 2.45.2