update doc.
[chise/ruby.git] / src / chise / char.rb
1 #!/usr/bin/env ruby
2 # Ruby/CHISE module by eto 2002-1114
3 # $Id: char.rb,v 1.1 2003-11-10 08:11:46 eto Exp $
4 # Copyright (C) 2002-2003 Kouichirou Eto, All rights reserved.
5 # This is free software with ABSOLUTELY NO WARRANTY.
6 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
7
8 require 'uconv'
9 require 'singleton'
10 $LOAD_PATH << '../../src' if $0 == __FILE__
11 require 'chise/db'
12
13 $KCODE = 'u' #今のところこれ以外では動かない。String.splitが影響大。inspectも影響。
14 $debug = false #これはテスト用
15 $debug = true #これはテスト用
16 $stdout.binmode if $debug
17 $stdout.sync = true if $debug
18
19 class String #======================================================================
20   def to_a() self.split(//) end #$KCODEが設定されているので、UTF-8的な一文字づつがchにはいる
21   def each_char() to_a.each {|ch| yield ch } end
22   def each_character() to_a.each {|ch| yield ch.char } end
23   def char_length() to_a.length end
24   def char_at(n) to_a()[n] end
25   def first_char() to_a[0] end
26   def char() Character.get(to_a[0]) end
27   #alias to_c char #悩み中
28   #def char_id() char.char_id() end #なんとなく廃止
29   #def get_char_attribute(a) char.get_char_attribute(a) end #なんとなく廃止
30   #def ucs() char.ucs() end
31   def to_utf8()
32     return to_a.map {|ch|
33       ch.char.to_utf8
34     }.join('')
35   end
36
37   def map_char(block = Proc.new)
38     return unless block_given?
39     return self.to_a.map {|ch| (block.call(ch)).to_s }.join("")
40   end
41   def map_char!(block = Proc.new)
42     return unless block_given?
43     self.replace(self.map_char {|ch| block.call(ch)})
44   end
45   def map_character(block = Proc.new)
46     return unless block_given?
47     return self.to_a.map {|ch| (block.call(ch.char)).to_s }.join("")
48   end
49   def map_character!(block = Proc.new)
50     return unless block_given?
51     self.replace(self.map_char {|ch| block.call(ch.char)})
52   end
53
54   def method_missing(mid, *args)
55     if char_length == 1 #省略形が有効なのは、一文字の時だけ
56       char.method_missing(mid, *args)
57     else
58       raise NameError, "undefined method `#{mid.id2name}'", caller(1)
59     end
60   end
61
62   def map_utf8() map_char {|ch| ch.char.map_utf8 } end
63   alias map_ucs map_utf8
64   def map_ucs_er() map_char {|ch| ch.char.map_ucs_er } end
65   def to_er() map_char {|ch| ch.char.to_er } end
66
67   #put関係、[]関係は用意しないことにした。
68   def de_er!() #EntityReferenceを取り除く
69     return self unless self =~ Regexp.new(EntityReference::REGEXP_PART) #それらしいのが無ければ何もしない
70     er = "&"+$1+";"      
71     self.sub!(Regexp.new(Regexp.escape(er)), Character.new(er).mcs_utf8) #変換自体はCharacterにまかせる
72     return self.de_er! if self =~ Regexp.new(EntityReference::REGEXP_PART) #まだあったら再帰
73     return self
74   end
75   def de_er() return self.dup.de_er!; end
76
77   def inspect_all() map_char {|ch| ch.char.inspect_all } end
78   def inspect_x()   map_char {|ch| ch.char.inspect_x   } end
79
80   def to_euc()   map_char {|ch| ch.char.to_euc   } end
81   def map_euc()  map_char {|ch| ch.char.map_euc  } end
82   def to_sjis()  map_char {|ch| ch.char.to_sjis  } end
83   def map_sjis() map_char {|ch| ch.char.map_sjis } end
84
85   def glyph_decompose() map_char {|ch| ch.char.glyph_decompose } end
86   def decompose() map_char {|ch| ch.char.decompose } end
87   def decompose!() self.replace(self.decompose); self; end
88   def decompose_all_nu(level=nil)
89     level = 0 if level.nil?
90     if 10 < level
91       p ['too many recursive', self] 
92       exit
93     end
94     de = self.decompose
95     return de.decompose_all(level+1) if de != self #なにか変化があったから再帰
96     de #もうこれ以上変化は無さそうだぞと。
97   end
98   def decompose_all() map_char {|ch| ch.char.decompose_all } end
99   def decompose_all!() self.replace(self.decompose_all); self; end
100
101   def find() #"日雲"→"曇"とかいう感じの操作
102     ar = []
103     length = char_length()
104     each_char {|ch|
105       char = ch.char
106       ar << char.ids_contained #その文字を含んでいる漢字のリスト
107     }
108     h = Hash.new(0)
109     ar.each {|list|
110       next if list.nil?
111       list.each_char {|ch|
112         h[ch] += 1
113       }
114     }
115     str = ""
116     h.each {|k, v|
117       #      p [k, v]
118       if length == v #全部に顔を出していたら
119         str += k
120       end
121     }
122     #    p str
123     str
124   end
125   def compose()
126     db = CodesysDB.instance
127     composed = db.get('ids', self)
128     return "" if composed.nil? #なかったよと。
129     return "" if composed.char_length == 0 #なにごと?
130     return composed if composed.char_length == 1
131     composed.each_char {|ch|
132       char = ch.char
133       return ch if char.has_attribute? #とりあえず最初にみつかったものを返すというヌルい仕様
134     }
135     return "" #attributeを持つものが一つも無かったら、""にする
136   end
137   def aggregate()
138     #selfである文字列をIDSだと仮定し、それを完全にcomposeしきらないで、
139     #その部分集合だけをとりだして、compose可能であればできるだけcomposeする。
140     tree = IDS_Tree.new(self)
141     return self if tree.depth <= 1 #sub_nodesが無い場合はここでさよなら
142     tree.sub_nodes.each {|node|
143       c = node.compose
144       next if c.nil? || c == ""
145       #      print "#{self}     #{node} #{c}\n"
146       #      p [self, node, c]
147       n = self.gsub(node, c)
148       return n.aggregate
149     }
150     return self #おきかえられるものがまったくなかったら、自分をかえす。
151   end
152 end
153
154 module CHISE #======================================================================
155   def windows?()
156     (RUBY_PLATFORM =~ /cygwin/ || RUBY_PLATFORM =~ /mswin32/ || RUBY_PLATFORM =~ /mingw32/)
157   end
158   module_function :windows?
159   if windows?()
160     DB_DIR = 'd:/work/chise/char-db' #この後に/sysmtem-char-id/ucsという感じに続く
161     IDS_DB_DIR = 'd:/work/chise/ids/' #この後にIDS-JIS-X0208-1990.txtという感じに続く
162   else
163     DB_DIR = '/usr/local/lib/xemacs-21.4.12/i686-pc-linux/char-db' #この後に/sysmtem-char-id/ucsという感じに続く
164     IDS_DB_DIR = '/home/eto/work/chise/ids/' #この後にIDS-JIS-X0208-1990.txtという感じに続く
165   end
166
167   class EntityReference #======================================================================
168     #状況によってどのERに変換するかが異なる可能性があるので、普通のclassとして実装したほうがいい?
169 #    CODESYS_TABLE = [
170 #      %w( chinese-big5-cdp     CDP- 4 X),
171 #      %w( ideograph-daikanwa   M-   5 d),
172 #      %w( ideograph-cbeta      CB   5 d),
173 #      %w( ideograph-gt         GT-  5 d),
174 #      %w( ideograph-gt-k       GT-K 5 d),
175 #      %w( japanese-jisx0208-1990 J90- 4 X),
176 #      %w( japanese-jisx0208    J83- 4 X),
177 #      %w( japanese-jisx0213-1  JX1- 4 X),
178 #      %w( japanese-jisx0213-2  JX2- 4 X),
179 #      %w( japanese-jisx0212    JSP- 4 X),
180 #      %w( japanese-jisx0208-1978 J78- 4 X),
181 #      %w( chinese-cns11643-1   C1-  4 X),
182 #      %w( chinese-cns11643-2   C2-  4 X),
183 #      %w( chinese-cns11643-3   C3-  4 X),
184 #      %w( chinese-cns11643-4   C4-  4 X),
185 #      %w( chinese-cns11643-5   C5-  4 X),
186 #      %w( chinese-cns11643-6   C6-  4 X),
187 #      %w( chinese-cns11643-7   C7-  4 X),
188 #      %w( korean-ksc5601       K0- 4 X),
189 #    ]
190 #    CODESYS_ORDER = %w(japanese chinese korean ideograph)
191     CODESYS_TABLE = [
192       %w( =jis-x0208-1990       J90- 4 X),
193       %w( =jis-x0208-1983       J83- 4 X),
194       %w( =jis-x0208-1978       J78- 4 X),
195       %w( =jis-x0208            J90- 4 X), #継承のアドホックな実装
196       %w( =jis-x0208            J83- 4 X), #継承のアドホックな実装
197       %w( =jis-x0208            J78- 4 X), #継承のアドホックな実装
198       %w( =jis-x0213-1-2000     JX1- 4 X),
199       %w( =jis-x0213-2-2000     JX2- 4 X),
200       %w( =jis-x0212            JSP- 4 X),
201       %w( =big5-cdp             CDP- 4 X),
202       %w( =cns11643-1           C1-  4 X),
203       %w( =cns11643-2           C2-  4 X),
204       %w( =cns11643-3           C3-  4 X),
205       %w( =cns11643-4           C4-  4 X),
206       %w( =cns11643-5           C5-  4 X),
207       %w( =cns11643-6           C6-  4 X),
208       %w( =cns11643-7           C7-  4 X),
209       %w( =ks-x1001             K0-  4 X),
210       %w( =daikanwa             M-   5 d),
211       %w( =cbeta                CB   5 d),
212       %w( =gt                   GT-  5 d),
213       %w( =gt-k                 GT-K 5 d),
214     ]
215     REGEXP_PART = "&([-+0-9A-Za-z#]+);"
216     REGEXP_ALL = "^#{REGEXP_PART}$"
217
218     def self.match?(er) (er =~ Regexp.new(REGEXP_PART)) != nil end
219
220     def self.parse(er) #char_idをFIXNUMで返す
221       return "" unless er =~ Regexp.new(REGEXP_ALL) #なんか、間違ってる?
222       er = $1 #ついでに中身の部分を取り出す
223       return $1.hex if er =~ /^MCS-([0-9A-Fa-f]+)/ #MCS
224       #      if er =~ /^U[-+]?([0-9A-Fa-f]+)/ #Unicode直打ち
225       if er =~ /^U[-+]?([0-9A-Fa-f]+)/ || er =~ /^#x([0-9A-Fa-f]+)/ #Unicode直打ち
226         return $1.hex 
227       end
228
229       er.sub!(/^I-/, '') if er =~ /^I-/ #I-がついてるとどう違うのかはよくわからない
230       each_codesys {|codesys, er_prefix, keta, numtype| #p [codesys, er_prefix, keta, numtype]
231         numtyperegex = '\d' #if numtype == 'd'
232         numtyperegex = '[0-9A-Fa-f]' if numtype == 'X'
233         regexpstr = "^#{er_prefix}(#{numtyperegex}{#{keta},#{keta}})$"
234         if er =~ Regexp.new(regexpstr)
235           codestr = $1
236           code = codestr.to_i #if numtype == 'd'
237           code = codestr.hex if numtype == 'X'
238           char_id_u8 = EntityReference.get_database(codesys, code)
239           char_id_num = Character.parse_char_id(char_id_u8)
240           next if char_id_num == nil
241           return char_id_num
242         end
243       }
244       return ""
245     end
246
247     def self.each_codesys()
248 #      CODESYS_ORDER.each {|lang|
249 #       CODESYS_TABLE.each {|codesys, er_prefix, keta, numtype| #普通こういう書き方はしない。ループ一個にする。
250 #         next unless codesys =~ lang
251 #         yield(codesys, er_prefix, keta, numtype)
252 #       }
253 #      }
254       CODESYS_TABLE.each {|codesys, er_prefix, keta, numtype|
255         yield(codesys, er_prefix, keta, numtype)
256       }
257     end
258     def self.get_database(codesys, code)
259       c = CodesysDB.instance.get(codesys, code)
260       return c if c != nil
261 #      if codesys =~ /-jisx0208/
262 #       #return self.get_database("=jis-x0208", code) #再帰でどうだ?
263 #       c = CodesysDB.instance.get("=jis-x0208", code)
264 #       return c
265 #      end
266       return nil
267     end
268   end
269
270   class CharacterFactory #============================================文字オブジェクトの生成、cache
271     include Singleton
272     MAX = 10000
273     def initialize
274       @max = MAX
275       reset()
276     end
277     def get(char_id)
278       check_max()
279       n = Character.parse_char_id(char_id)
280       c = @chars[n]
281       @chars[n] = Character.new(n) if @chars[n] == nil
282       return @chars[n]
283     end
284     def reset()
285       @chars = nil
286       @chars = Hash.new
287       GC.start #ガーベージコレクション
288     end
289     def length() @chars.length; end
290     def check_max()
291       reset if @max < @chars.length #MAXを超えたらresetしてしまう。乱暴じゃがcacheなのでこれでいいのだ。
292     end
293   end
294
295   class Character #=============================================================== 文字オブジェクト
296     def initialize(char_id=nil)
297       @char_id = Character.parse_char_id(char_id)
298       @attributes = Hash.new
299       @check_all_database = false
300     end
301     attr_reader :char_id
302     def to_i() @char_id end
303     def mcs_utf8() Character.u4itou8(@char_id) end
304     def mcs_hex() sprintf("%x", @char_id) end
305
306     #----------------------------------------------------------------------
307     def self.get(char_id) CharacterFactory.instance.get(char_id) end #flyweightパターン
308
309     #----------------------------------------------------------------------
310     def normalize_attribute_name(b)
311       a = b.dup
312       a.gsub!(/_/, '-') #underlineは-に置換
313       a.sub!(/-at-/,  '@')
314       a.sub!(/^map-/,  '=>')
315       a.sub!(/^to-/,   '->')
316       a.sub!(/^from-/, '<-')
317       a
318     end
319     def get_char_attribute(b) # XEmacs UTF-2000互換API群
320       a = normalize_attribute_name(b)
321       #p [a, b]
322       atr = @attributes[a]
323       return atr if atr
324       atr = check_database(a)
325       if atr
326         @attributes[a] = atr
327         return atr
328       end
329       return get_char_attribute("="+a) unless a =~ /^=/ #頭に=がついてない場合はそれが省略されていることを仮定して、再帰する
330       nil
331     end
332     def put_char_attribute(b,v)
333       a = normalize_attribute_name(b)
334       @attributes[a] = v;
335       CharDB.instance.put(a, mcs_utf8(), v)
336     end
337     def char_attribute_alist() check_all_database(); @attributes; end
338     def char_attribute_list()  check_all_database(); @attributes.keys; end
339     alias [] get_char_attribute  #その略称
340     alias []= put_char_attribute
341     alias alist char_attribute_alist
342     alias list  char_attribute_list
343
344     def method_missing(mid, *args) #参考:ostruct.rb
345       mname = mid.id2name
346       return get_char_attribute(mname) if args.length == 0
347       put_char_attribute(mname.chop, args[0]) if mname =~ /=$/ #代入
348     end
349
350     def has_attribute?() #意味のあるattributeを持ってますか?
351       keys = list
352       keys.delete_if {|k|
353         k =~ /ids/
354       }
355       return (keys.length != 0)
356     end
357
358     #----------------------------------------------------------------------
359     def ==(ch)
360       return false if ch == nil
361       return false unless ch.is_a? Character
362       self.char_id == ch.char_id
363     end
364
365     #----------------------------------------------------------------------
366     def self.parse_char_id(char_id) #FIXNUMを返す
367       return nil if char_id == nil
368       if char_id.is_a?(Numeric) #p [char_id]
369         char_id = 0x80000000 + char_id if char_id < 0  #補数表現
370         return char_id.to_i
371       elsif char_id.is_a?(String)
372         return char_id.to_i if char_id =~ /^\d+$/ && 1 < char_id.length #文字列による数字だったら数値化してreturn
373         return EntityReference.parse(char_id) if char_id =~ Regexp.new(EntityReference::REGEXP_ALL) #実体参照?
374         char_id.sub!(/^\?/, '') if char_id =~ /^\?/ #もし先頭に?がついていたら削除
375         #このへん本当はもっとちゃんとチェックするべし
376         begin
377           u4 = Uconv.u8tou4(char_id) #UCS-4文字列に変換
378         rescue
379           p $!
380           p char_id
381           return 0
382         end
383         return Character.u4tou4i(u4) #UCS-4数値にしてreturn
384       else
385         raise ArgumentError, "unknown object for char_id", caller(1)
386       end
387     end
388     def self.u4tou4i(u4)
389       return 0 if u4 == nil || u4 == ""
390       return (u4[3] << 24 | u4[2] << 16 | u4[1] << 8 | u4[0]) #UCS-4数値にしてreturn
391     end
392     def self.u4itou4(num)
393       return "" unless num.is_a?(Integer)
394       return sprintf("%c%c%c%c", num&0xff, (num >> 8)&0xff, (num >> 16)&0xff, (num >> 24)&0xff) #UCS-4数値を文字列にしてreturn
395     end
396     def self.u4itou8(char_id) #ucsの数値を受けとり、UTF-8の文字一文字を返す
397       begin
398         u4 = Character.u4itou4(char_id)
399         u8 = Uconv.u4tou8(u4)
400         return u8
401       rescue
402         #raise ArgumentError, "invalid char_id (#{char_id})", caller(1)
403         #print "error\n"
404         return ""
405       end
406     end
407
408     #----------------------------------------------------------------------
409     def check_database(a)
410       db = CharDB.instance
411       u8 = mcs_utf8()
412       v = db.get(a, u8) #u8で表される文字のaアトリビュートを調べる。
413       return v
414     end
415     def check_all_database() #現在の@char_idから、文字データベースを参照する
416       return if @check_all_database
417       return if @char_id == nil
418       db = CharDB.instance
419       u8 = mcs_utf8()
420       atrs = db.get_all(u8) #u8で表される文字のアトリビュートを全部持ってこい
421       atrs.each {|a,v|
422         @attributes[a] = v #とかいう感じで代入するのでええかな?
423       }
424       @check_all_database = true #重い処理なので一応checkする
425     end
426
427     #----------------------------------------------------------------------
428     def ucs()      #p 'ucs'
429       #ar = %w{ucs ucs-big5 ucs-cdp ucs-cns ucs-jis ucs-ks =>ucs =>ucs* =>ucs-jis}
430       #ar = %w{ucs ucs-jis ucs-big5 ucs-cdp ucs-cns ucs-ks =>ucs =>ucs* =>ucs-jis}
431       ar = %w{ucs-jis ucs =>ucs-jis}
432       #並び順は恣意的で、ucs-jisを先に出している。本来はこれも指定できるようにするべき。
433       ar.each {|a|      #p [a]
434         u = get_char_attribute(a)
435         return u if u != nil
436       }
437       return nil
438     end
439
440     #----------------------------------------------------------------------CCS関係
441     def to_utf8() Uconv.u4tou8(Character.u4itou4(ucs())) end #UTF8文字列を返す
442     #alias to_s to_utf8
443     alias to_s mcs_utf8
444     def map_utf8()
445       u = ucs()
446       if u.nil? || 0xffff < u
447         return to_er()
448       else
449         return to_utf8()
450       end
451     end
452     alias map_ucs map_utf8
453     def map_ucs_er()
454       u = ucs()
455       if u.nil? || 0xffff < u
456         return to_er()
457       else
458         return Character.get(u).to_er()
459       end
460     end
461     def to_euc()
462       u = ucs()
463       return "" if u.nil? || 0xffff < u
464       Uconv.u16toeuc(Uconv.u4tou16(Character.u4itou4(ucs())))
465     end
466     def map_euc()
467       e = to_euc()
468       return e if e != ""
469       return to_er()
470     end
471     def to_sjis()
472       u = ucs()
473       return "" if u.nil? || 0xffff < u
474       Uconv.u16tosjis(Uconv.u4tou16(Character.u4itou4(ucs())))
475     end
476     def map_sjis()
477       e = to_sjis()
478       return e if e != ""
479       return to_er()
480     end
481
482     #----------------------------------------------------------------------
483     def to_er(codesys=nil) #実体参照を返す、希望するcodesysが引数(未実装)
484       return "" if @char_id == nil
485       return sprintf("&#x%04x;", @char_id) if @char_id <= 0xffff
486       return sprintf("&#x%05x;", @char_id) if @char_id <= 0xfffff
487       EntityReference.each_codesys {|codesys, er_prefix, keta, numtype|
488         code = self[codesys]
489         next if code == nil
490         return sprintf("&#{er_prefix}%0#{keta}#{numtype};", code)
491       }
492       return sprintf("&MCS-%08X;", @char_id) #本当はこれは無しにしたい
493     end
494     def to_er_list()
495       ar = []
496       EntityReference.each_codesys {|codesys, er_prefix, keta, numtype|
497         er = to_er(codesys)
498         ar << er if er != nil
499       }
500       ar
501     end
502
503     def inspect_x()
504       return "<>" if @char_id == nil
505       ar = [to_utf8(), to_er().sub(/^&/,'').chop]
506       "<"+ar.join(',')+">"
507     end
508     alias inspect inspect_x
509     def inspect_all_codesys() #未完成
510       #to_erを全てのcodesysにおいて実行する。その結果をコンパクトにまとめる
511     end
512     def inspect_all()
513       ar = [inspect.chop]
514       alist.to_a.sort.each {|a, v| ar << "#{a}:#{v}" }
515       return ar.join(',')+">"
516     end
517     def dump_all()
518       ar = [inspect]
519       alist.to_a.sort.each {|a, v| ar << "#{a}:#{v}" }
520       return ar.join('\n')+'\n'
521     end
522     def get_attributes()
523       str = ""
524       alist.to_a.sort.each {|a, v|
525         str += "#{a}: #{v}\n"
526       }
527       str
528     end
529
530     def inspect_ids(hex_flag=false)
531       ids = decompose
532       ar = []
533       ar << (hex_flag ? "x"+mcs_hex : to_utf8)
534       if to_s != ids #idsが部品そのものだったら部品追加はしない
535         ids.each_char {|ch|
536           char = ch.char
537           next if char.is_ids?
538           if hex_flag then
539             ar << "x"+char.mcs_hex
540           else
541             u = char.to_utf8
542             if u != ""
543               ar << u
544             else
545               ar << char.to_er
546             end
547           end
548         }
549       end
550       return "("+ar.join("\t")+")"
551     end
552
553     #----------------------------------------------------------------------IDS関係
554     def glyph_decompose() do_decompose(false) end
555     def decompose()       do_decompose(true)  end
556     def do_decompose(check_meaning = true)
557       k = self.to_s
558       #       idss = self['ids']
559       #       return idss if idss
560       #       return k if self.is_basic_kanji? #基本漢字はstop kanjiとするぞと。
561       if check_meaning
562         return self['ids-represent'] if self['ids-represent'] #ids_representを持っている場合はその値とする。
563         return self['ids-element'] if self['ids-element'] #ids_elementを持っている場合はその値とする。
564         idss = self['ids-meaning']
565         return idss if idss != nil && 0 < idss.length && k != idss
566       end
567       idss = self['ids-aggregated']
568       return idss if idss != nil && 0 < idss.length && k != idss
569       idss = self['ids']
570       return idss if idss != nil && 0 < idss.length && k != idss
571       return k
572       #       return k if idss.nil? || idss.length == 0 || k == idss
573       #       if idss.char_length == 2
574       # p ['What???', k, idss, k.inspect_all]
575       #  #return idssx[1] #二個目だけ返すとか?
576       #  return k #IDSに展開する方法が無いと。
577       #       end
578       #       return k if k == idss
579       #       if idss.include?(k) #<C5-4C4D><C6-4A37>この二文字のBUG対策
580       #  #return idss.sub(k, '')
581       #  return k #IDSに展開する方法が無いと。
582       #       end
583       #       return idss
584     end
585     def decompose_all
586       pde = ""
587       de = self.decompose #出発点
588       level = 0
589       while true
590         pde = de
591         de = pde.decompose #もう一度分解をしてみる。
592         break if pde == de #ループを抜けだす
593         exit if 10 < level #p ['too many recursive', self] 
594         level += 1
595       end
596       return de
597     end
598     def decompose_all_nu(level=nil)
599       level = 0 if level.nil?
600       if 10 < level
601         p ['too many recursive', self] 
602         exit
603       end
604       de = self.decompose
605       return de.decompose_all(level+1) if de != self #なにか変化があったから再帰
606       return de #もうこれ以上変化は無さそうだぞと。
607     end
608     def is_ids?() 0x2ff0 <= @char_id && @char_id <= 0x2fff end
609     def ids_operator_argc()
610       return 0 unless is_ids?
611       return 3 if @char_id == 0x2ff2 || @char_id == 0x2ff3
612       return 2
613     end
614   end
615
616 end
617
618 #----------------------------------------------------------------------終了