summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/utf8proc/data/data_generator.rb
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/utf8proc/data/data_generator.rb')
-rwxr-xr-x[-rw-r--r--]3rdparty/utf8proc/data/data_generator.rb128
1 files changed, 96 insertions, 32 deletions
diff --git a/3rdparty/utf8proc/data/data_generator.rb b/3rdparty/utf8proc/data/data_generator.rb
index 97c9033a419..91cc03d0b40 100644..100755
--- a/3rdparty/utf8proc/data/data_generator.rb
+++ b/3rdparty/utf8proc/data/data_generator.rb
@@ -6,6 +6,8 @@
# production use.
+# Copyright (c) 2018 Steven G. Johnson, Tony Kelman, Keno Fischer,
+# Benito van der Zander, Michaël Meyer, and other contributors.
# Copyright (c) 2009 Public Software Group e. V., Berlin, Germany
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -65,7 +67,7 @@
# authorization of the copyright holder.
-$ignorable_list = File.read("DerivedCoreProperties.txt")[/# Derived Property: Default_Ignorable_Code_Point.*?# Total code points:/m]
+$ignorable_list = File.read("DerivedCoreProperties.txt", :encoding => 'utf-8')[/# Derived Property: Default_Ignorable_Code_Point.*?# Total code points:/m]
$ignorable = []
$ignorable_list.each_line do |entry|
if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)/
@@ -75,7 +77,53 @@ $ignorable_list.each_line do |entry|
end
end
-$grapheme_boundclass_list = File.read("GraphemeBreakProperty.txt")
+$uppercase_list = File.read("DerivedCoreProperties.txt", :encoding => 'utf-8')[/# Derived Property: Uppercase.*?# Total code points:/m]
+$uppercase = []
+$uppercase_list.each_line do |entry|
+ if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)/
+ $1.hex.upto($2.hex) { |e2| $uppercase << e2 }
+ elsif entry =~ /^[0-9A-F]+/
+ $uppercase << $&.hex
+ end
+end
+
+$lowercase_list = File.read("DerivedCoreProperties.txt", :encoding => 'utf-8')[/# Derived Property: Lowercase.*?# Total code points:/m]
+$lowercase = []
+$lowercase_list.each_line do |entry|
+ if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)/
+ $1.hex.upto($2.hex) { |e2| $lowercase << e2 }
+ elsif entry =~ /^[0-9A-F]+/
+ $lowercase << $&.hex
+ end
+end
+
+$icb_linker_list = File.read("DerivedCoreProperties.txt", :encoding => 'utf-8')[/# Indic_Conjunct_Break=Linker.*?# Total code points:/m]
+$icb = Hash.new("UTF8PROC_INDIC_CONJUNCT_BREAK_NONE")
+$icb_linker_list.each_line do |entry|
+ if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)/
+ $1.hex.upto($2.hex) { |e2| $icb[e2] = "UTF8PROC_INDIC_CONJUNCT_BREAK_LINKER" }
+ elsif entry =~ /^[0-9A-F]+/
+ $icb[$&.hex] = "UTF8PROC_INDIC_CONJUNCT_BREAK_LINKER"
+ end
+end
+$icb_consonant_list = File.read("DerivedCoreProperties.txt", :encoding => 'utf-8')[/# Indic_Conjunct_Break=Consonant.*?# Total code points:/m]
+$icb_consonant_list.each_line do |entry|
+ if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)/
+ $1.hex.upto($2.hex) { |e2| $icb[e2] = "UTF8PROC_INDIC_CONJUNCT_BREAK_CONSONANT" }
+ elsif entry =~ /^[0-9A-F]+/
+ $icb[$&.hex] = "UTF8PROC_INDIC_CONJUNCT_BREAK_CONSONANT"
+ end
+end
+$icb_extend_list = File.read("DerivedCoreProperties.txt", :encoding => 'utf-8')[/# Indic_Conjunct_Break=Extend.*?# Total code points:/m]
+$icb_extend_list.each_line do |entry|
+ if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)/
+ $1.hex.upto($2.hex) { |e2| $icb[e2] = "UTF8PROC_INDIC_CONJUNCT_BREAK_EXTEND" }
+ elsif entry =~ /^[0-9A-F]+/
+ $icb[$&.hex] = "UTF8PROC_INDIC_CONJUNCT_BREAK_EXTEND"
+ end
+end
+
+$grapheme_boundclass_list = File.read("GraphemeBreakProperty.txt", :encoding => 'utf-8')
$grapheme_boundclass = Hash.new("UTF8PROC_BOUNDCLASS_OTHER")
$grapheme_boundclass_list.each_line do |entry|
if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)\s*;\s*([A-Za-z_]+)/
@@ -85,7 +133,20 @@ $grapheme_boundclass_list.each_line do |entry|
end
end
-$charwidth_list = File.read("CharWidths.txt")
+$emoji_data_list = File.read("emoji-data.txt", :encoding => 'utf-8')
+$emoji_data_list.each_line do |entry|
+ if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)\s*;\s*Extended_Pictographic\W/
+ $1.hex.upto($2.hex) { |e2| $grapheme_boundclass[e2] = "UTF8PROC_BOUNDCLASS_EXTENDED_PICTOGRAPHIC" }
+ elsif entry =~ /^([0-9A-F]+)\s*;\s*Extended_Pictographic\W/
+ $grapheme_boundclass[$1.hex] = "UTF8PROC_BOUNDCLASS_EXTENDED_PICTOGRAPHIC"
+ elsif entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)\s*;\s*Emoji_Modifier\W/
+ $1.hex.upto($2.hex) { |e2| $grapheme_boundclass[e2] = "UTF8PROC_BOUNDCLASS_EXTEND" }
+ elsif entry =~ /^([0-9A-F]+)\s*;\s*Emoji_Modifier\W/
+ $grapheme_boundclass[$1.hex] = "UTF8PROC_BOUNDCLASS_EXTEND"
+ end
+end
+
+$charwidth_list = File.read("CharWidths.txt", :encoding => 'utf-8')
$charwidth = Hash.new(0)
$charwidth_list.each_line do |entry|
if entry =~ /^([0-9A-F]+)\.\.([0-9A-F]+)\s*;\s*([0-9]+)/
@@ -95,16 +156,16 @@ $charwidth_list.each_line do |entry|
end
end
-$exclusions = File.read("CompositionExclusions.txt")[/# \(1\) Script Specifics.*?# Total code points:/m]
+$exclusions = File.read("CompositionExclusions.txt", :encoding => 'utf-8')[/# \(1\) Script Specifics.*?# Total code points:/m]
$exclusions = $exclusions.chomp.split("\n").collect { |e| e.hex }
-$excl_version = File.read("CompositionExclusions.txt")[/# \(2\) Post Composition Version precomposed characters.*?# Total code points:/m]
+$excl_version = File.read("CompositionExclusions.txt", :encoding => 'utf-8')[/# \(2\) Post Composition Version precomposed characters.*?# Total code points:/m]
$excl_version = $excl_version.chomp.split("\n").collect { |e| e.hex }
-$case_folding_string = File.open("CaseFolding.txt", :encoding => 'utf-8').read
+$case_folding_string = File.read("CaseFolding.txt", :encoding => 'utf-8')
$case_folding = {}
$case_folding_string.chomp.split("\n").each do |line|
- next unless line =~ /([0-9A-F]+); [CFS]; ([0-9A-F ]+);/i
+ next unless line =~ /([0-9A-F]+); [CF]; ([0-9A-F ]+);/i
$case_folding[$1.hex] = $2.split(" ").collect { |e| e.hex }
end
@@ -137,15 +198,15 @@ def cpary2utf16encoded(array)
end
def cpary2c(array)
return "UINT16_MAX" if array.nil? || array.length == 0
- lencode = array.length - 1 #no sequence has len 0, so we encode len 1 as 0, len 2 as 1, ...
+ lencode = array.length - 1 #no sequence has len 0, so we encode len 1 as 0, len 2 as 1, ...
array = cpary2utf16encoded(array)
- if lencode >= 7 #we have only 3 bits for the length (which is already cutting it close. might need to change it to 2 bits in future Unicode versions)
- array = [lencode] + array
- lencode = 7
- end
- idx = pushary(array)
- raise "Array index out of bound" if idx > 0x1FFF
- return "#{idx | (lencode << 13)}"
+ if lencode >= 3 #we have only 2 bits for the length
+ array = [lencode] + array
+ lencode = 3
+ end
+ idx = pushary(array)
+ raise "Array index out of bound" if idx > 0x3FFF
+ return "#{idx | (lencode << 14)}"
end
def singlecpmap(cp)
return "UINT16_MAX" if cp == nil
@@ -188,9 +249,12 @@ class UnicodeChar
@decomp_mapping = ($8=='') ? nil :
$8.split.collect { |element| element.hex }
@bidi_mirrored = ($13=='Y') ? true : false
- @uppercase_mapping = ($16=='') ? nil : $16.hex
- @lowercase_mapping = ($17=='') ? nil : $17.hex
- @titlecase_mapping = ($18=='') ? nil : $18.hex
+ # issue #130: use nonstandard uppercase ß -> ẞ
+ # issue #195: if character is uppercase but has no lowercase mapping,
+ # then make lowercase mapping = itself (vice versa for lowercase)
+ @uppercase_mapping = ($16=='') ? (code==0x00df ? 0x1e9e : ($17=='' && $lowercase.include?(code) ? code : nil)) : $16.hex
+ @lowercase_mapping = ($17=='') ? ($16=='' && $uppercase.include?(code) ? code : nil) : $17.hex
+ @titlecase_mapping = ($18=='') ? (code==0x00df ? 0x1e9e : nil) : $18.hex
end
def case_folding
$case_folding[code]
@@ -211,7 +275,8 @@ class UnicodeChar
"#{$ignorable.include?(code)}, " <<
"#{%W[Zl Zp Cc Cf].include?(category) and not [0x200C, 0x200D].include?(category)}, " <<
"#{$charwidth[code]}, 0, " <<
- "#{$grapheme_boundclass[code]}},\n"
+ "#{$grapheme_boundclass[code]}, " <<
+ "#{$icb[code]}},\n"
end
end
@@ -260,17 +325,17 @@ chars.each do |char|
end
unless comb2nd_indicies[dm1]
comb2nd_indicies_sorted_keys << dm1
- comb2nd_indicies[dm1] = comb2nd_indicies.keys.length
+ comb2nd_indicies[dm1] = comb2nd_indicies.keys.length
end
comb_array[comb1st_indicies[dm0]] ||= []
raise "Duplicate canonical mapping: #{char.code} #{dm0} #{dm1}" if comb_array[comb1st_indicies[dm0]][comb2nd_indicies[dm1]]
comb_array[comb1st_indicies[dm0]][comb2nd_indicies[dm1]] = char.code
-
+
comb2nd_indicies_nonbasic[dm1] = true if char.code > 0xFFFF
end
char.c_decomp_mapping = cpary2c(char.decomp_mapping)
char.c_case_folding = cpary2c(char.case_folding)
-end
+end
comb_indicies = {}
cumoffset = 0
@@ -281,7 +346,7 @@ comb1st_indicies.each do |dm0, index|
last = nil
offset = 0
comb2nd_indicies_sorted_keys.each_with_index do |dm1, b|
- if comb_array[index][b]
+ if comb_array[index][b]
first = offset unless first
last = offset
last += 1 if comb2nd_indicies_nonbasic[dm1]
@@ -340,7 +405,7 @@ for code in 0...0x110000
end
end
-$stdout << "const utf8proc_uint16_t utf8proc_sequences[] = {\n "
+$stdout << "static const utf8proc_uint16_t utf8proc_sequences[] = {\n "
i = 0
$int_array.each do |entry|
i += 1
@@ -352,7 +417,7 @@ $int_array.each do |entry|
end
$stdout << "};\n\n"
-$stdout << "const utf8proc_uint16_t utf8proc_stage1table[] = {\n "
+$stdout << "static const utf8proc_uint16_t utf8proc_stage1table[] = {\n "
i = 0
stage1.each do |entry|
i += 1
@@ -364,7 +429,7 @@ stage1.each do |entry|
end
$stdout << "};\n\n"
-$stdout << "const utf8proc_uint16_t utf8proc_stage2table[] = {\n "
+$stdout << "static const utf8proc_uint16_t utf8proc_stage2table[] = {\n "
i = 0
stage2.flatten.each do |entry|
i += 1
@@ -376,8 +441,8 @@ stage2.flatten.each do |entry|
end
$stdout << "};\n\n"
-$stdout << "const utf8proc_property_t utf8proc_properties[] = {\n"
-$stdout << " {0, 0, 0, 0, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, false,false,false,false, 0, 0, UTF8PROC_BOUNDCLASS_OTHER},\n"
+$stdout << "static const utf8proc_property_t utf8proc_properties[] = {\n"
+$stdout << " {0, 0, 0, 0, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, false,false,false,false, 1, 0, UTF8PROC_BOUNDCLASS_OTHER, UTF8PROC_INDIC_CONJUNCT_BREAK_NONE},\n"
properties.each { |line|
$stdout << line
}
@@ -385,13 +450,13 @@ $stdout << "};\n\n"
-$stdout << "const utf8proc_uint16_t utf8proc_combinations[] = {\n "
+$stdout << "static const utf8proc_uint16_t utf8proc_combinations[] = {\n "
i = 0
comb1st_indicies.keys.each_index do |a|
offset = 0
$stdout << comb1st_indicies_firstoffsets[a] << ", " << comb1st_indicies_lastoffsets[a] << ", "
comb2nd_indicies_sorted_keys.each_with_index do |dm1, b|
- break if offset > comb1st_indicies_lastoffsets[a]
+ break if offset > comb1st_indicies_lastoffsets[a]
if offset >= comb1st_indicies_firstoffsets[a]
i += 1
if i == 8
@@ -403,9 +468,8 @@ comb1st_indicies.keys.each_index do |a|
$stdout << (v & 0xFFFF) << ", "
end
offset += 1
- offset += 1 if comb2nd_indicies_nonbasic[dm1]
+ offset += 1 if comb2nd_indicies_nonbasic[dm1]
end
$stdout << "\n"
end
$stdout << "};\n\n"
-