diff options
author | Karl Berry <karl@freefriends.org> | 2020-03-26 21:59:35 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-03-26 21:59:35 +0000 |
commit | 6718ddef228e265e1229ab24336b433213b81db2 (patch) | |
tree | 76ade7bee4f6c4f4f281117fc1b421299d2fb235 /Master/texmf-dist/source/generic/hyph-utf8/lib/tex/hyphen/converter.rb | |
parent | 26b61329ccfef7f8de119d7cf2ae772288e1497d (diff) |
hyph-utf8, with tlpsrc from arthur
git-svn-id: svn://tug.org/texlive/trunk@54568 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/generic/hyph-utf8/lib/tex/hyphen/converter.rb')
-rw-r--r-- | Master/texmf-dist/source/generic/hyph-utf8/lib/tex/hyphen/converter.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/generic/hyph-utf8/lib/tex/hyphen/converter.rb b/Master/texmf-dist/source/generic/hyph-utf8/lib/tex/hyphen/converter.rb new file mode 100644 index 00000000000..3b966d45a40 --- /dev/null +++ b/Master/texmf-dist/source/generic/hyph-utf8/lib/tex/hyphen/converter.rb @@ -0,0 +1,39 @@ +# encoding: UTF-8 + +require 'scanf' +require 'byebug' + +module TeX + module Hyphen + class Converter + def read(conversion) + @mapping = { } + File.read(conversion).each_line do |line| + next if line =~ /^#/ + + eightbit, usv = line.scanf "0x%02X\tU+%04X" + @mapping[eightbit] = usv.chr(Encoding::UTF_8) + end + end + + def convert(filename) + raise "Please define the encoding mapping first with #read" unless @mapping + doconvert = false + File.open(filename, external_encoding: Encoding::ASCII_8BIT).each_line do |line| + if line =~ /\\patterns{/ + doconvert = true + next + end + doconvert = false if doconvert && line =~ /}/ + + if doconvert + puts (line.strip.each_byte.map do |byte| + byebug unless @mapping[byte] + @mapping[byte] + end || '').join + end + end + end + end + end +end |