[前][次][番号順一覧][スレッド一覧]

ruby-changes:8303

From: duerst <ko1@a...>
Date: Sat, 18 Oct 2008 17:11:13 +0900 (JST)
Subject: [ruby-changes:8303] Ruby:r19831 (trunk): * tool/transcode-tblgen.rb: added set_valid_byte_pattern

duerst	2008-10-18 17:10:57 +0900 (Sat, 18 Oct 2008)

  New Revision: 19831

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19831

  Log:
    * tool/transcode-tblgen.rb: added set_valid_byte_pattern
      to reduce coupling between table generation script and
      specific encodings.
    
    * enc/trans/single_byte.trans: using set_valid_byte_pattern

  Modified files:
    trunk/ChangeLog
    trunk/enc/trans/single_byte.trans
    trunk/tool/transcode-tblgen.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19830)
+++ ChangeLog	(revision 19831)
@@ -1,3 +1,11 @@
+Tue Oct 14 17:10:10 2008  Martin Duerst  <duerst@i...>
+
+	* tool/transcode-tblgen.rb: added set_valid_byte_pattern
+	  to reduce coupling between table generation script and
+	  specific encodings.
+
+	* enc/trans/single_byte.trans: using set_valid_byte_pattern
+
 Tue Oct 14 16:39:39 2008  Martin Duerst  <duerst@i...>
 
 	* transcode.c: in transcode_search_path, elimintated a warning
Index: enc/trans/single_byte.trans
===================================================================
--- enc/trans/single_byte.trans	(revision 19830)
+++ enc/trans/single_byte.trans	(revision 19831)
@@ -27,6 +27,7 @@
   transcode_tblgen "UTF-8", "ASCII-8BIT", us_ascii_map
 
   def transcode_tblgen_singlebyte(name, tbl_to_ucs)
+    set_valid_byte_pattern(name, '1byte')
     code = ''
     code << transcode_tblgen(name, "UTF-8", [["{00-7f}", :nomap], *tbl_to_ucs])
     code << "\n"
Index: tool/transcode-tblgen.rb
===================================================================
--- tool/transcode-tblgen.rb	(revision 19830)
+++ tool/transcode-tblgen.rb	(revision 19831)
@@ -726,29 +726,24 @@
                     {81-fe}{30-39}{81-fe}{30-39}',
 }
 
-{
-  'ASCII-8BIT'  => '1byte',
-  'ISO-8859-1'  => '1byte',
-  'ISO-8859-2'  => '1byte',
-  'ISO-8859-3'  => '1byte',
-  'ISO-8859-4'  => '1byte',
-  'ISO-8859-5'  => '1byte',
-  'ISO-8859-6'  => '1byte',
-  'ISO-8859-7'  => '1byte',
-  'ISO-8859-8'  => '1byte',
-  'ISO-8859-9'  => '1byte',
-  'ISO-8859-10' => '1byte',
-  'ISO-8859-11' => '1byte',
-  'ISO-8859-13' => '1byte',
-  'ISO-8859-14' => '1byte',
-  'ISO-8859-15' => '1byte',
-  'WINDOWS-1252' => '1byte',
-  'Windows-31J' => 'Shift_JIS',
-  'eucJP-ms'    => 'EUC-JP'
-}.each {|k, v|
-  ValidEncoding[k] = ValidEncoding.fetch(v)
-}
+def set_valid_byte_pattern (encoding, pattern_or_label)
+  pattern =
+    if ValidEncoding[pattern_or_label]
+      ValidEncoding[pattern_or_label]
+    else
+      pattern_or_label
+    end
+  if ValidEncoding[encoding] and ValidEncoding[encoding]!=pattern
+    raise ArgumentError, "trying to change valid byte pattern for encoding #{encoding} from #{ValidEncoding[encoding]} to #{pattern}"
+  end
+  ValidEncoding[encoding] = pattern
+end
 
+# the following may be used in different places, so keep them here for the moment
+set_valid_byte_pattern 'ASCII-8BIT', '1byte'
+set_valid_byte_pattern 'Windows-31J', 'Shift_JIS'
+set_valid_byte_pattern 'eucJP-ms', 'EUC-JP'
+
 def make_signature(filename, src)
   "src=#{filename.dump}, len=#{src.length}, checksum=#{src.sum}"
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]