Giter VIP home page Giter VIP logo

Comments (7)

BurntSushi avatar BurntSushi commented on June 22, 2024 1

xsv table doesn't print the parsed contents of CSV data. It just rewrites the input CSV as tab-delimited CSV, and then expands the tabs in the output as per elastic tabstops. This is easy to see in the implementation:

xsv/src/cmd/table.rs

Lines 49 to 71 in 4278b85

pub fn run(argv: &[&str]) -> CliResult<()> {
let args: Args = util::get_args(USAGE, argv)?;
let rconfig = Config::new(&args.arg_input)
.delimiter(args.flag_delimiter)
.no_headers(true);
let wconfig = Config::new(&args.flag_output)
.delimiter(Some(Delimiter(b'\t')));
let tw = TabWriter::new(wconfig.io_writer()?)
.minwidth(args.flag_width)
.padding(args.flag_pad);
let mut wtr = wconfig.from_writer(tw);
let mut rdr = rconfig.reader()?;
let mut record = csv::ByteRecord::new();
while rdr.read_byte_record(&mut record)? {
wtr.write_record(record.iter().map(|f| {
util::condense(Cow::Borrowed(f), args.flag_condense)
}))?;
}
wtr.flush()?;
Ok(())
}

It does seem plausible that it would be better to print the parsed contents (i.e., after unescaping quotes).

from xsv.

BurntSushi avatar BurntSushi commented on June 22, 2024 1

xsv table doesn't print the parsed contents of CSV data. It just rewrites the input CSV as tab-delimited CSV, and then expands the tabs in the output as per elastic tabstops. This is easy to see in the implementation:

xsv/src/cmd/table.rs

Lines 49 to 71 in 4278b85

pub fn run(argv: &[&str]) -> CliResult<()> {
let args: Args = util::get_args(USAGE, argv)?;
let rconfig = Config::new(&args.arg_input)
.delimiter(args.flag_delimiter)
.no_headers(true);
let wconfig = Config::new(&args.flag_output)
.delimiter(Some(Delimiter(b'\t')));
let tw = TabWriter::new(wconfig.io_writer()?)
.minwidth(args.flag_width)
.padding(args.flag_pad);
let mut wtr = wconfig.from_writer(tw);
let mut rdr = rconfig.reader()?;
let mut record = csv::ByteRecord::new();
while rdr.read_byte_record(&mut record)? {
wtr.write_record(record.iter().map(|f| {
util::condense(Cow::Borrowed(f), args.flag_condense)
}))?;
}
wtr.flush()?;
Ok(())
}

It does seem plausible that it would be better to print the parsed contents (i.e., after unescaping quotes).

I ran into something similar for xsv fmt --ascii. Printing the parsed contents would be much more useful of a feature; one turns to ASV precisely so that you don't need to escape strings!

xsv fmt --ascii should definitely not print the parsed contents. It should print CSV data. And insert quoting when necessary. But it does look like it is inserting quotes when it shouldn't for --ascii.

from xsv.

Kinrany avatar Kinrany commented on June 22, 2024

The thing that confused me the most was that it does remove the quotes around "a".

Is the output of xsv table intended to be parseable as CSV too?

from xsv.

BurntSushi avatar BurntSushi commented on June 22, 2024

The thing that confused me the most was that it does remove the quotes around "a".

Yes, because the CSV writer knows when quotes are necessary. They aren't necessary to write a.

Is the output of xsv table intended to be parseable as CSV too?

No. As I said, the tabs are expanded to spaces. So it's very deliberately not CSV. It's for human consumption. Which is arguably why this should be treated as a bug and the quotes should be unescaped.

from xsv.

Kinrany avatar Kinrany commented on June 22, 2024

That's what I thought!

Can I help? Xsv is a great tool 😄

from xsv.

vmchale avatar vmchale commented on June 22, 2024

xsv table doesn't print the parsed contents of CSV data. It just rewrites the input CSV as tab-delimited CSV, and then expands the tabs in the output as per elastic tabstops. This is easy to see in the implementation:

xsv/src/cmd/table.rs

Lines 49 to 71 in 4278b85

pub fn run(argv: &[&str]) -> CliResult<()> {
let args: Args = util::get_args(USAGE, argv)?;
let rconfig = Config::new(&args.arg_input)
.delimiter(args.flag_delimiter)
.no_headers(true);
let wconfig = Config::new(&args.flag_output)
.delimiter(Some(Delimiter(b'\t')));
let tw = TabWriter::new(wconfig.io_writer()?)
.minwidth(args.flag_width)
.padding(args.flag_pad);
let mut wtr = wconfig.from_writer(tw);
let mut rdr = rconfig.reader()?;
let mut record = csv::ByteRecord::new();
while rdr.read_byte_record(&mut record)? {
wtr.write_record(record.iter().map(|f| {
util::condense(Cow::Borrowed(f), args.flag_condense)
}))?;
}
wtr.flush()?;
Ok(())
}

It does seem plausible that it would be better to print the parsed contents (i.e., after unescaping quotes).

I ran into something similar for xsv fmt --ascii. Printing the parsed contents would be much more useful of a feature; one turns to ASV precisely so that you don't need to escape strings!

from xsv.

Kinrany avatar Kinrany commented on June 22, 2024

xsv fmt --table? 🤔

from xsv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.