--- util-old.rb 2010-05-11 21:38:55.736596584 +0300 +++ util.rb 2010-05-12 00:33:16.128001053 +0300 @@ -3,6 +3,7 @@ require 'mime/types' require 'pathname' require 'set' +require 'console/string' ## time for some monkeypatching! class Lockfile def gen_lock_id @@ -177,16 +178,12 @@ end class String - ## 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 RUBY_VERSION < '1.9.1' && ($encoding == "UTF-8" || $encoding == "utf8") - scan(/./u).size - else - size - end + display_width end + def camel_to_hyphy self.gsub(/([a-z])([A-Z0-9])/, '\1-\2').downcase end @@ -270,14 +267,17 @@ def wrap len ret = [] s = self - while s.length > len - cut = s[0 ... len].rindex(/\s/) - if cut - ret << s[0 ... cut] - s = s[(cut + 1) .. -1] + while s.display_width > len + cut = s.display_slice(0,len," ") + # find the last space, since display slices it precisely + space = cut.rindex(/\s/) + space = cut.size unless space #No spaces? + cut = s[0 ... space] + ret << cut + if space != cut.size #+1 to kill the space in the beginning of next line + s = s[(cut.size + 1) .. -1] else - ret << s[0 ... len] - s = s[len .. -1] + s = s[cut.size .. -1] end end ret << s