]> git.cworth.org Git - sup/commitdiff
make multibyte display "work" for non-utf8 locales
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 15 Jun 2009 15:00:07 +0000 (08:00 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 15 Jun 2009 15:00:52 +0000 (08:00 -0700)
A nasty hack, but fixes a previous utf8-centric change.

lib/sup.rb
lib/sup/util.rb

index 96510b2e2d7419629a0a3fd3e9d96eafca29c36e..7444df0912ceefc9e2b36622802f184d2eaae0af 100644 (file)
@@ -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)
index 8a3004f4f5561ae715588514b7414e3b4cb2a5a6..ece52babe4cb1e8ea3f2970d290ab10f4a64fc1a 100644 (file)
@@ -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