case-folding.rb: check version numbers
* enc/unicode/case-folding.rb: check if version numbers in each data files match. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7d4db05679
commit
753ce99eac
@ -45,7 +45,7 @@ class CaseFolding
|
|||||||
|
|
||||||
include Util
|
include Util
|
||||||
|
|
||||||
attr_reader :fold, :fold_locale, :unfold, :unfold_locale
|
attr_reader :fold, :fold_locale, :unfold, :unfold_locale, :version
|
||||||
|
|
||||||
def load(filename)
|
def load(filename)
|
||||||
pattern = /([0-9A-F]{4,6}); ([CFT]); ([0-9A-F]{4,6})(?: ([0-9A-F]{4,6}))?(?: ([0-9A-F]{4,6}))?;/
|
pattern = /([0-9A-F]{4,6}); ([CFT]); ([0-9A-F]{4,6})(?: ([0-9A-F]{4,6}))?(?: ([0-9A-F]{4,6}))?;/
|
||||||
@ -53,9 +53,11 @@ class CaseFolding
|
|||||||
@fold = fold = {}
|
@fold = fold = {}
|
||||||
@unfold = unfold = [{}, {}, {}]
|
@unfold = unfold = [{}, {}, {}]
|
||||||
@debug = false
|
@debug = false
|
||||||
|
@version = nil
|
||||||
turkic = []
|
turkic = []
|
||||||
|
|
||||||
IO.foreach(filename, mode: "rb") do |line|
|
IO.foreach(filename, mode: "rb") do |line|
|
||||||
|
@version ||= line[/-([0-9.]+).txt/, 1]
|
||||||
next unless res = pattern.match(line)
|
next unless res = pattern.match(line)
|
||||||
ch_from = res[1].to_i(16)
|
ch_from = res[1].to_i(16)
|
||||||
|
|
||||||
@ -202,11 +204,14 @@ class MapItem
|
|||||||
end
|
end
|
||||||
|
|
||||||
class CaseMapping
|
class CaseMapping
|
||||||
def initialize (mapping_directory)
|
attr_reader :filename, :version
|
||||||
|
|
||||||
|
def initialize(mapping_directory)
|
||||||
@mappings = {}
|
@mappings = {}
|
||||||
@specials = []
|
@specials = []
|
||||||
@specials_length = 0
|
@specials_length = 0
|
||||||
IO.readlines(File.expand_path('UnicodeData.txt', mapping_directory), encoding: Encoding::ASCII_8BIT).each do |line|
|
@version = nil
|
||||||
|
IO.foreach(File.join(mapping_directory, 'UnicodeData.txt'), mode: "rb") do |line|
|
||||||
next if line =~ /^</
|
next if line =~ /^</
|
||||||
code, _1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11, upper, lower, title = line.chomp.split ';'
|
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)==''
|
unless upper and lower and title and (upper+lower+title)==''
|
||||||
@ -214,7 +219,9 @@ class CaseMapping
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
IO.readlines(File.expand_path('SpecialCasing.txt', mapping_directory), encoding: Encoding::ASCII_8BIT).each do |line|
|
@filename = File.join(mapping_directory, 'SpecialCasing.txt')
|
||||||
|
IO.foreach(@filename, mode: "rb") do |line|
|
||||||
|
@version ||= line[/-([0-9.]+).txt/, 1]
|
||||||
line.chomp!
|
line.chomp!
|
||||||
line, comment = line.split(/ *#/)
|
line, comment = line.split(/ *#/)
|
||||||
next if not line or line == ''
|
next if not line or line == ''
|
||||||
@ -353,13 +360,18 @@ if $0 == __FILE__
|
|||||||
warn "Either specify directory or individual file, but not both."
|
warn "Either specify directory or individual file, but not both."
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
filename = File.expand_path('CaseFolding.txt', mapping_directory)
|
filename = File.join(mapping_directory, 'CaseFolding.txt')
|
||||||
mapping_data = CaseMapping.load(mapping_directory)
|
mapping_data = CaseMapping.load(mapping_directory)
|
||||||
end
|
end
|
||||||
filename ||= ARGV[0] || 'CaseFolding.txt'
|
filename ||= ARGV[0] || 'CaseFolding.txt'
|
||||||
|
data = CaseFolding.load(filename)
|
||||||
|
if mapping_data and data.version != mapping_data.version
|
||||||
|
abort "Unicode data version mismatch\n" \
|
||||||
|
" #{filename} = #{data.version}\n" \
|
||||||
|
" #{mapping_data.filename} = #{mapping_data.version}"
|
||||||
|
end
|
||||||
mapping_data ||= CaseMappingDummy.new
|
mapping_data ||= CaseMappingDummy.new
|
||||||
|
|
||||||
data = CaseFolding.load(filename)
|
|
||||||
if debug
|
if debug
|
||||||
data.debug!
|
data.debug!
|
||||||
mapping_data.debug!
|
mapping_data.debug!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user