From 7aaf5b2878210d4df03a84be8d514a553839a5ba Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Nov 2018 06:44:02 +0000 Subject: Embed the Emoji version git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/enc-unicode.rb | 65 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 23 deletions(-) (limited to 'tool/enc-unicode.rb') diff --git a/tool/enc-unicode.rb b/tool/enc-unicode.rb index b0819c35ab..f64cecb881 100755 --- a/tool/enc-unicode.rb +++ b/tool/enc-unicode.rb @@ -18,7 +18,11 @@ unless ARGV.size == 2 abort "Usage: #{$0} data_directory emoji_data_directory" end -$unicode_version = File.basename(ARGV[0])[/\A[.\d]+\z/] +pat = /(?:\A|\/)([.\d]+)\z/ +$versions = { + :Unicode => ARGV[0][pat, 1], + :Emoji => ARGV[1][pat, 1], +} POSIX_NAMES = %w[NEWLINE Alpha Blank Cntrl Digit Graph Lower Print XPosixPunct Space Upper XDigit Word Alnum ASCII Punct] @@ -307,18 +311,30 @@ end def data_foreach(name, &block) fn = get_file(name) warn "Reading #{name}" - pat = /^# #{File.basename(name).sub(/\./, '-([\\d.]+)\\.')}/ + if /^emoji-/ =~ name + sep = "" + pat = /^# #{Regexp.quote(File.basename(name))}.*^# Version: ([\d.]+)/m + type = :Emoji + else + sep = "\n" + pat = /^# #{File.basename(name).sub(/\./, '-([\\d.]+)\\.')}/ + type = :Unicode + end File.open(fn, 'rb') do |f| - line = f.gets - unless /^emoji-/ =~ name - unless pat =~ line - raise ArgumentError, "#{name}: no Unicode version" - end - if !$unicode_version - $unicode_version = $1 - elsif $unicode_version != $1 - raise ArgumentError, "#{name}: Unicode version mismatch: #$1" - end + line = f.gets(sep) + unless version = line[pat, 1] + raise ArgumentError, <<-ERROR +#{name}: no #{type} version +#{line.gsub(/^/, '> ')} + ERROR + end + if !(v = $versions[type]) + $versions[type] = version + elsif v != version + raise ArgumentError, <<-ERROR +#{name}: #{type} version mismatch: #{version} to #{v} +#{line.gsub(/^/, '> ')} + ERROR end f.each(&block) end @@ -510,17 +526,20 @@ uniname2ctype(const UChar *name, unsigned int len) return -1; } __HEREDOC -versions = $unicode_version.scan(/\d+/) -print("#if defined ONIG_UNICODE_VERSION_STRING && !( \\\n") -%w[MAJOR MINOR TEENY].zip(versions) do |n, v| - print(" ONIG_UNICODE_VERSION_#{n} == #{v} && \\\n") -end -print(" 1)\n") -print("# error ONIG_UNICODE_VERSION_STRING mismatch\n") -print("#endif\n") -print("#define ONIG_UNICODE_VERSION_STRING #{$unicode_version.dump}\n") -%w[MAJOR MINOR TEENY].zip(versions) do |n, v| - print("#define ONIG_UNICODE_VERSION_#{n} #{v}\n") +$versions.each do |type, ver| + name = type == :Unicode ? "ONIG_UNICODE_VERSION" : "ONIG_UNICODE_EMOJI_VERSION" + versions = ver.scan(/\d+/) + print("#if defined #{name}_STRING && !( \\\n") + versions.zip(%w[MAJOR MINOR TEENY]) do |v, n| + print(" #{name}_#{n} == #{v} && \\\n") + end + print(" 1)\n") + print("# error #{name}_STRING mismatch\n") + print("#endif\n") + print("#define #{name}_STRING #{ver.dump}\n") + versions.zip(%w[MAJOR MINOR TEENY]) do |v, n| + print("#define #{name}_#{n} #{v}\n") + end end output.restore -- cgit v1.2.1