update.
[chise/ruby.git] / chise / chisedb.rb
index 7d7715e..4b930a1 100755 (executable)
@@ -9,7 +9,7 @@ module CHISE
       return nil if v.nil?
       return v.to_i if /\A\d+\Z/ =~ v # number?
       return $1 if /\A"(.+)"\Z/ =~ v # remove surrounding "
-      v # sexp?
+      v # sexp? or the other?
     end
   end
 
@@ -22,7 +22,8 @@ module CHISE
       setup_ds
       @feature_db = {}
       @ccs_db = {}
-      @byids_db = {}
+      # @byids_db = {}
+      @ccsstr_db = {}
     end
     attr_reader :ds, :location
 
@@ -37,7 +38,6 @@ module CHISE
     end
 
     def each_feature_name()
-#      setup_ds
       @ds.each_feature_name {|f|
        next if f.to_s == "." || f.to_s == ".."
        next if f.to_s =~ /\.txt\Z/
@@ -46,40 +46,40 @@ module CHISE
     end
 
     def each_ccs
-#      setup_ds
       each_entry("character/by_feature") {|f| yield(f) }
     end
 
     def get_feature(name)
-#      setup_ds
       @feature_db[name] = FeatureDB.new(self, name) if @feature_db[name].nil?
       @feature_db[name]
     end
 
     def load_feature(cid, name)
-#      setup_ds
       feature = get_feature(name)
       feature.get_value(cid)
     end
 
     def get_ccs(name)
-#      setup_ds
       @ccs_db[name] = CCS_DB.new(self, name) if @ccs_db[name].nil?
       @ccs_db[name]
     end
 
     def decode_char(ccs, code_point)
-#      setup_ds
       ccsdb = get_ccs(ccs)
       ccsdb.decode(code_point)
     end
 
-    def get_by_ids_db(n)
-#      setup_ds
+    def nuget_by_ids_db(n)
       @byids_db[n] = ByIDS_DB.new(self, n) if @byids_db[n].nil?
       @byids_db[n]
     end
 
+    def get_ccs_str(n)
+      @ccsstr_db[n] = CCS_STR.new(self, n) if @ccsstr_db[n].nil?
+#      @ccsstr_db[n] = CCS_STR_DB.new(self, n) if @ccsstr_db[n].nil?
+      @ccsstr_db[n]
+    end
+
     private
     include EachEntryModule
   end
@@ -124,7 +124,7 @@ module CHISE
     alias close sync
 
     def set_value(cid, value)
-      @feature.set_value(cid, value)
+      @feature.set_value(cid, value.to_s)
     end
 
     def get_value(cid)
@@ -173,7 +173,7 @@ module CHISE
     end
   end
 
-  class ByIDS_DB
+  class CCS_STR_DB
     include ParseValueModule
     include ChiseValue
     include TableAccessModule
@@ -189,16 +189,16 @@ module CHISE
       }
     end
 
-    def decode(ids)
+    def get_by_str(str)
       setup_db
       return nil if @db.nil?
-      parse_c_string(@db.get(ids))
+      parse_c_string(@db.get(str))
     end
 
-    def set_decoded_char(ids, cid)
+    def set_by_str(str, cid)
       setup_db(true)
       raise "@db is nil." if @db.nil?
-      @db.put(ids, format_char_id(cid))
+      @db.put(str, format_char_id(cid))
     end
 
     def each_char
@@ -209,4 +209,5 @@ module CHISE
       }
     end
   end
+
 end