add config file
[chise/ruby.git] / lib / chise / char.rb
index f0b5651..1b9fe9f 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 # Ruby/CHISE module by eto 2002-1114
-# $Id: char.rb,v 1.2 2003-11-10 08:38:12 eto Exp $
+# $Id: char.rb,v 1.3 2003-11-30 13:16:38 eto Exp $
 # Copyright (C) 2002-2003 Kouichirou Eto, All rights reserved.
 # This is free software with ABSOLUTELY NO WARRANTY.
 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
@@ -9,15 +9,21 @@ require 'uconv'
 require 'singleton'
 $LOAD_PATH << '../../lib' if $0 == __FILE__
 require 'chise/db'
+require 'chise/config'
 
-$KCODE = 'u' #今のところこれ以外では動かない。String.splitが影響大。inspectも影響。
+#$KCODE = 'u' #今のところこれ以外では動かない。String.splitが影響大。inspectも影響。
 $debug = false #これはテスト用
 $debug = true #これはテスト用
 $stdout.binmode if $debug
 $stdout.sync = true if $debug
 
 class String #======================================================================
-  def to_a() self.split(//) end #$KCODEが設定されているので、UTF-8的な一文字づつがchにはいる
+  def to_a()
+    k = $KCODE;        $KCODE = 'u'
+    ar = self.split(//) #$KCODEによりUTF-8的な一文字づつがarに入る
+    $KCODE = k
+    ar
+  end
   def each_char() to_a.each {|ch| yield ch } end
   def each_character() to_a.each {|ch| yield ch.char } end
   def char_length() to_a.length end
@@ -77,9 +83,9 @@ class String #==================================================================
   def inspect_all() map_char {|ch| ch.char.inspect_all } end
   def inspect_x()   map_char {|ch| ch.char.inspect_x   } end
 
-  def to_euc()   map_char {|ch| ch.char.to_euc   } end
+#  def to_euc()   map_char {|ch| ch.char.to_euc   } end
   def map_euc()  map_char {|ch| ch.char.map_euc  } end
-  def to_sjis()  map_char {|ch| ch.char.to_sjis  } end
+#  def to_sjis()  map_char {|ch| ch.char.to_sjis  } end
   def map_sjis() map_char {|ch| ch.char.map_sjis } end
 
   def glyph_decompose() map_char {|ch| ch.char.glyph_decompose } end
@@ -157,11 +163,11 @@ module CHISE #==================================================================
   end
   module_function :windows?
   if windows?()
-    DB_DIR = 'd:/work/chise/char-db' #この後に/sysmtem-char-id/ucsという感じに続く
-    IDS_DB_DIR = 'd:/work/chise/ids/' #この後にIDS-JIS-X0208-1990.txtという感じに続く
+    DB_DIR = Config.instance.db_dir #この後に/sysmtem-char-id/ucsという感じに続く
+    IDS_DB_DIR = Config.instance.ids_dir #この後にIDS-JIS-X0208-1990.txtという感じに続く
   else
     DB_DIR = '/usr/local/lib/xemacs-21.4.12/i686-pc-linux/char-db' #この後に/sysmtem-char-id/ucsという感じに続く
-    IDS_DB_DIR = '/home/eto/work/chise/ids/' #この後にIDS-JIS-X0208-1990.txtという感じに続く
+    IDS_DB_DIR = '/home/eto/chise/ids/' #この後にIDS-JIS-X0208-1990.txtという感じに続く
   end
 
   class EntityReference #======================================================================
@@ -224,6 +230,10 @@ module CHISE #==================================================================
       #      if er =~ /^U[-+]?([0-9A-Fa-f]+)/ #Unicode直打ち
       if er =~ /^U[-+]?([0-9A-Fa-f]+)/ || er =~ /^#x([0-9A-Fa-f]+)/ #Unicode直打ち
        return $1.hex 
+      elsif er =~ /^#([0-9]+)/ #Unicode直打ち
+       return $1.to_i
+      elsif er =~ /^my-([0-9]+)/i #マイ文字コード
+       return (0xe000 + $1.to_i)
       end
 
       er.sub!(/^I-/, '') if er =~ /^I-/ #I-がついてるとどう違うのかはよくわからない