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

ruby-changes:41694

From: duerst <ko1@a...>
Date: Sun, 7 Feb 2016 22:10:17 +0900 (JST)
Subject: [ruby-changes:41694] duerst:r53767 (trunk): * common.mk: Added two more precondition files for enc/unicode/casefold.h

duerst	2016-02-07 22:10:20 +0900 (Sun, 07 Feb 2016)

  New Revision: 53767

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53767

  Log:
    * common.mk: Added two more precondition files for enc/unicode/casefold.h
    * enc/unicode.c: Added shortening macros for enc/unicode/casefold.h
    * enc/unicode/case-folding.rb: Fixed file encoding for CaseFolding.txt
      to ASCII-8BIT (should fix some ci errors). Clarified usage. Created
      class MapItem. Partially implemented class CaseMapping.
    (with Kimihito Matsui)

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/enc/unicode/case-folding.rb
    trunk/enc/unicode.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53766)
+++ ChangeLog	(revision 53767)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Feb  7 22:10:08 2016  Martin Duerst  <duerst@i...>
+
+	* common.mk: Added two more precondition files for enc/unicode/casefold.h
+
+	* enc/unicode.c: Added shortening macros for enc/unicode/casefold.h
+
+	* enc/unicode/case-folding.rb: Fixed file encoding for CaseFolding.txt
+	  to ASCII-8BIT (should fix some ci errors). Clarified usage. Created
+	  class MapItem. Partially implemented class CaseMapping.
+	(with Kimihito Matsui)
+
 Sun Feb  7 14:12:32 2016  Martin Duerst  <duerst@i...>
 
 	* enc/unicode/case-folding.rb: Fixing parameter passing.
Index: enc/unicode.c
===================================================================
--- enc/unicode.c	(revision 53766)
+++ enc/unicode.c	(revision 53767)
@@ -140,8 +140,18 @@ code3_equal(const OnigCodePoint *x, cons https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L140
   return 1;
 }
 
+#define UP    ONIGENC_CASE_UPCASE
+#define DOWN  ONIGENC_CASE_DOWNCASE
+#define TITLE ONIGENC_CASE_TITLECASE
+#define FOLD  ONIGENC_CASE_FOLD
+
 #include "enc/unicode/casefold.h"
 
+#undef UP
+#undef DOWN
+#undef TITLE
+#undef FOLD
+
 #include "enc/unicode/name2ctype.h"
 
 #define CODE_RANGES_NUM numberof(CodeRanges)
Index: enc/unicode/case-folding.rb
===================================================================
--- enc/unicode/case-folding.rb	(revision 53766)
+++ enc/unicode/case-folding.rb	(revision 53767)
@@ -1,10 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/enc/unicode/case-folding.rb#L1
 #!/usr/bin/ruby
 
-# Usage:
+# Usage (for case folding only):
 #   $ wget http://www.unicode.org/Public/UNIDATA/CaseFolding.txt
 #   $ ruby case-folding.rb CaseFolding.txt -o casefold.h
-#  or:
+#  or (for case folding and case mapping):
 #   $ wget http://www.unicode.org/Public/UNIDATA/CaseFolding.txt
+#   $ wget http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
+#   $ wget http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt
 #   $ ruby case-folding.rb -m . -o casefold.h
 
 class CaseFolding
@@ -175,12 +177,37 @@ class CaseFolding https://github.com/ruby/ruby/blob/trunk/enc/unicode/case-folding.rb#L177
   end
 end
 
+class MapItem
+  def initialize(code, upper, lower, title)
+    @code = code
+    @upper = upper unless upper == ''
+    @lower = lower unless lower == ''
+    @title = title unless title == ''
+  end
+  
+  def flags
+    "" # preliminary implementation
+  end
+end
+
 class CaseMapping
   def initialize (mapping_directory)
+    @mappings = {}
+    IO.readlines(File.expand_path('UnicodeData.txt', mapping_directory), encoding: Encoding::ASCII_8BIT).each do |line|
+      next if line =~ /</
+      code, _1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11, upper, lower, title = line.chomp.split ';'
+      unless upper and lower and title and (upper+lower+title)==''
+        @mappings[code] = MapItem.new(code, upper, lower, title)
+      end
+      
+    end
+    
+    # IO.readlines(File.expand_path('SpecialCasing.txt', mapping_directory))
   end
 
   def flags(from)
-    "" # preliminary implementation
+    to = @mappings[from]
+    to ? to.flags : ""
   end
 
   def self.load(*args)
@@ -216,7 +243,7 @@ if $0 == __FILE__ https://github.com/ruby/ruby/blob/trunk/enc/unicode/case-folding.rb#L243
       warn "Either specify directory or individual file, but not both."
       exit
     end
-    filename = File.expand_path("CaseFolding.txt", mapping_directory)
+    filename = File.expand_path('CaseFolding.txt', mapping_directory)
     mapping_data = CaseMapping.load(mapping_directory)
   end
   filename ||= ARGV[0] || 'CaseFolding.txt'
Index: common.mk
===================================================================
--- common.mk	(revision 53766)
+++ common.mk	(revision 53767)
@@ -1048,6 +1048,8 @@ $(srcdir)/.unicode-tables.time: $(srcdir https://github.com/ruby/ruby/blob/trunk/common.mk#L1048
 		$(UNICODE_DATA_DIR) lib/unicode_normalize
 
 $(srcdir)/enc/unicode/casefold.h: $(srcdir)/enc/unicode/case-folding.rb \
+		$(UNICODE_SRC_DATA_DIR)/UnicodeData.txt \
+		$(UNICODE_SRC_DATA_DIR)/SpecialCasing.txt \
 		$(UNICODE_SRC_DATA_DIR)/CaseFolding.txt
 	$(Q) $(BASERUBY) $(srcdir)/enc/unicode/case-folding.rb \
 		--output-file=$(srcdir)/enc/unicode/casefold.h \

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

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