1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
5 require "chise/chisedb"
11 class CharacterFactory # generate Character object and cache them
14 MAX_CACHE_CHARACTER = 10000
18 @parser = CharacterParser.new
27 mcs = @parser.parse(s)
28 @chars[mcs] = Character.new(mcs) if @chars[mcs].nil?
33 clear if MAX_CACHE_CHARACTER < @chars.length # clear all cache
41 def initialize(char_id)
43 raise unless char_id.kind_of?(Integer) # make sure char_id is Integer.
44 raise if char_id < 0 # make sure char_id is positive.
47 # @utf8_mcs = CHISE.i_tou8(@char_id)
48 @utf8_mcs = itou8(@char_id)
57 CharacterFactory.instance.get(s)
61 sprintf("Char:%x", @char_id)
64 def to_s() @utf8_mcs; end
67 f = normalize_feature_name(f)
80 v = get_feature("="+f)
90 f = normalize_feature_name(k)
92 ft = cd.get_feature(f)
93 ft.set_value(@char_id, v)
97 def method_missing(mid, *args) # ref. ostruct.rb
100 return self[mname] if args.empty? # get
102 if args.length == 1 && /=\Z/ =~ mname # put
103 self[mname.chop] = args.shift
111 en = EntityReferenceEncoder.new
116 0x2ff0 <= @char_id && @char_id <= 0x2fff
119 def idc_argument_number
120 return 0 unless is_idc?
121 return 3 if @char_id == 0x2ff2 || @char_id == 0x2ff3
128 cd = ChiseDB.instance
129 cd.load_feature(f, @char_id)
132 def normalize_feature_name(a)
133 a = a.gsub(/_/, "-") #underlineは-に置換
134 a = a.sub(/-at-/, "@")
135 a = a.sub(/-plus-/, "+")
136 a = a.sub(/\Amap-/, "=>")
137 a = a.sub(/\Ato-/, "->")
138 a = a.sub(/\Afrom-/, "<-")