Skip to content

Commit

Permalink
Deal with unicode characters like the spec demands.
Browse files Browse the repository at this point in the history
Doesn't yet deal with negative numbers in \u
  • Loading branch information
MSch committed Sep 3, 2012
1 parent 80ae12a commit 99d60cc
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lib/ruby-rtf/parser.rb
Expand Up @@ -174,22 +174,13 @@ def handle_control(name, val, src, current_pos)
when :cf then add_section!(:foreground_colour => @doc.colour_table[val])
when :cb then add_section!(:background_colour => @doc.colour_table[val])
when :hex then current_section[:text] << val
when :uc then @skip_byte = val.to_i
when :uc then
raise "Can't deal with uc != 0 yet" if val != 0
when :u then
if @skip_byte && @skip_byte == 0
val = val % 100
@skip_byte = nil
end
if val == 32 || val == 8232
add_modifier_section({:newline => true}, "\n")
else
val += 65_536 if val < 0
char = if val < 10_000
[val.to_s.hex].pack('U*')
else
[val].pack('U*')
end
current_section[:text] << char
current_section[:text] << val.chr('utf-8')
end

when *[:rquote, :lquote] then add_modifier_section({name => true}, "'")
Expand Down

0 comments on commit 99d60cc

Please sign in to comment.