dont cut at the 18th character a string, if its utf8 it will be incorrect (happened...
authorgc <gc>
Thu, 17 Nov 2005 21:08:23 +0000 (21:08 +0000)
committergc <gc>
Thu, 17 Nov 2005 21:08:23 +0000 (21:08 +0000)
bin/booh-backend
lib/booh/booh-lib.rb

index c5dfb86..b63a3a4 100755 (executable)
@@ -660,7 +660,7 @@ def walk_source_dir
                 else
                     type = entry2type(file)
                     if type && !xmldir.elements["#{type}[@filename='#{utf8(file)}']"]
-                        xmldir.add_element type, { "filename" => utf8(file), "caption" => $empty_comments ? '' : utf8(file.sub(/\.[^\.]+$/, '')[0..17]) }
+                        xmldir.add_element type, { "filename" => utf8(file), "caption" => $empty_comments ? '' : utf8cut(file.sub(/\.[^\.]+$/, ''), 18) }
                     end
                 end
             end
index 984a786..991417a 100644 (file)
@@ -39,6 +39,14 @@ module Booh
         return Iconv::iconv("UTF-8", $CURRENT_CHARSET, string).to_s
     end
 
+    def utf8cut(string, maxlen)
+        begin
+            return Iconv::iconv("UTF-8", $CURRENT_CHARSET, string[0..maxlen-1]).to_s
+        rescue Iconv::InvalidCharacter
+            return utf8cut(string, maxlen-1)
+        end
+    end
+
     def sizename(key)
         #- fake for gettext to find these; if themes need more sizes, english name for them should be added here
         sizenames = { 'small' => utf8(_("small")), 'medium' => utf8(_("medium")), 'large' => utf8(_("large")),