mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-05 22:31:11 +08:00
Support for encodings other than UTF-8
This commit is contained in:
parent
1697360b6b
commit
eb13f2583f
@ -30,6 +30,7 @@ module YouPlot
|
||||
pass = parser.pass
|
||||
output = parser.output
|
||||
fmt = parser.fmt
|
||||
@encoding = parser.encoding
|
||||
@debug = parser.debug
|
||||
|
||||
if command == :colors
|
||||
@ -40,7 +41,12 @@ module YouPlot
|
||||
# Sometimes the input file does not end with a newline code.
|
||||
while (input = Kernel.gets(nil))
|
||||
input.freeze
|
||||
@data = Preprocessing.input(input, delimiter, headers, transpose)
|
||||
@data = if @encoding
|
||||
input2 = input.dup.force_encoding(@encoding).encode('utf-8')
|
||||
Preprocessing.input(input2, delimiter, headers, transpose)
|
||||
else
|
||||
Preprocessing.input(input, delimiter, headers, transpose)
|
||||
end
|
||||
pp @data if @debug
|
||||
plot = case command
|
||||
when :bar, :barplot
|
||||
|
@ -8,7 +8,7 @@ module YouPlot
|
||||
class Parser
|
||||
attr_reader :command, :params,
|
||||
:delimiter, :transpose, :headers, :pass, :output, :fmt,
|
||||
:color_names, :debug
|
||||
:color_names, :encoding, :debug
|
||||
|
||||
def initialize
|
||||
@command = nil
|
||||
@ -20,6 +20,7 @@ module YouPlot
|
||||
@pass = false
|
||||
@output = $stderr
|
||||
@fmt = 'xyy'
|
||||
@encoding = nil
|
||||
@debug = false
|
||||
@color_names = false
|
||||
end
|
||||
@ -81,6 +82,9 @@ module YouPlot
|
||||
opt.on('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', 'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
||||
@fmt = v
|
||||
end
|
||||
opt.on('--encoding VAL', String, 'Specify the input encoding') do |v|
|
||||
@encoding = v
|
||||
end
|
||||
# Optparse adds the help option, but it doesn't show up in usage.
|
||||
# This is why you need the code below.
|
||||
opt.on('--help', 'print sub-command help menu') do
|
||||
|
Loading…
Reference in New Issue
Block a user