Debian Codegraph @

tools/ucd-symbol-list.rb

raw symbols SCIP
1 #!/usr/bin/env ruby
2
3 base_dir = ARGV[0]
4
5 @targets = {}
6 def register(character_code, description)
7 @targets[character_code] = description
8 end
9
10 property_aliases = {}
11 File.open("#{base_dir}/PropertyValueAliases.txt") do |file|
12 file.each_line do |line|
13 case line
14 when /\A[a-z]/i
15 target, abbrev, name, = line.chomp.split(/\s*;\s*/)
16 next if abbrev == "n/a"
17 property_aliases[abbrev] = name
18 end
19 end
20 end
21
22 File.open("#{base_dir}/PropList.txt") do |file|
23 file.each_line do |line|
24 case line.chomp
25 when /\A([\da-f]{4,5})(?:\.\.([\da-f]{4,5})) +; .+? \# (.{2})/i
26 start = $1
27 last = $2
28 property_value_alias = $3
29 property_value = property_aliases[property_value_alias]
30 property_value ||= property_value_alias
31 case property_value
32 when "Dash_Punctuation",
33 "Open_Punctuation",
34 "Close_Punctuation",
35 "Connector_Punctuation",
36 "Other_Punctuation",
37 "Math_Symbol",
38 "Currency_Symbol",
39 "Modifier_Symbol",
40 "Other_Symbol"
41 if last.nil?
42 register(start.to_i(16), property_value)
43 else
44 (start.to_i(16)..last.to_i(16)).each do |character_code|
45 register(character_code, property_value)
46 end
47 end
48 end
49 end
50 end
51 end
52
53 File.open("#{base_dir}/Blocks.txt") do |file|
54 file.each_line do |line|
55 case line.chomp
56 when /\A([\da-f]{4,5})\.\.([\da-f]{4,5}); (.+)\z/i
57 start = $1
58 last = $2
59 description = $3
60 case description
61 when "CJK Symbols and Punctuation",
62 "Enclosed CJK Letters and Months",
63 "CJK Compatibility",
64 "CJK Compatibility Forms"
65 (start.to_i(16)..last.to_i(16)).each do |character_code|
66 register(character_code, description)
67 end
68 end
69 end
70 end
71 end
72
73 @targets.keys.sort.each do |character_code|
74 description = @targets[character_code]
75 character = [character_code].pack("U")
76 puts("%#x: %s: %s" % [character_code, character, description])
77 end