Last active
July 30, 2017 03:03
-
-
Save celadevra/8294149 to your computer and use it in GitHub Desktop.
Filter out uniq Chinese characters used in a text file. #ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
everything = "" | |
chars, charcodes = "" | |
File.open("main.md", "r") do |file| | |
while line = file.gets | |
everything << line | |
end | |
chinese_only = everything.gsub(/[\*()%:<>\-\/#\.\+\{\}!\[\]\s\w]+/, '') | |
chinese_array = chinese_only.scan(/./) | |
chars = chinese_array.uniq.join #=> string | |
charcodes = chinese_array.uniq.join | |
end | |
File.open("charsfile.txt", "w") do |file| | |
file.puts chars | |
end | |
File.open("subsetter", "w") do |file| | |
#charcodes.each_codepoint { |c| file.print(c.to_s, ' ') } | |
file.puts "#!/usr/bin/env fontforge" | |
file.puts "Open($1);" | |
file.puts "SelectAll();" | |
charcodes.each_codepoint { |c| file.print('SelectFewer(0u', c.to_s(16), ");\n") } | |
file.puts "DetachAndRemoveGlyphs();" | |
file.puts "Save($2);" | |
file.puts "Quit(0);" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment