Coder Social home page Coder Social logo

Comments (1)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 27, 2024
Trimming happens before unquoting. In the following I will replace spaces with 
_ for clarity.

Consider the following CSV-row:

"a",_"_b",_c 

There are several ways to read this data. The variants supported by the current 
code are the following:

Option 1: No unquoting, no trimming
1st = "a"
2nd = _"_b"
3rd = _c

Option 2: no unquoting, trimming
1st = "a"
2nd = "_b"
3rd = c

Option 3: unquoting, trimming
1st = a
2nd = _b
3rd = c

Option 4: unquoting, no trimming
1st = a
2nd = _"_b"
3rd = _c

What you want is another variant that is currently not directly supported:

Option 5:

1st = a
2nd = b
3rd = c

My feeling is that option 3 is more natural than option 5 as the CSV 
specifically encloses the space in the quotes. Further changing this might 
break existing code that relies on the current behavior. 

You can get pretty close to option 5 using the current code:

void my_trim(char*&str){
  while(*str == ' ')
    ++str;
  char*back = str+std::strlen(str);
  while(back != str && *(back-1) == ' '){
    --back;
    *back = '\0';
  }
}

...

char*str;
while(in.read_row(str)){
  my_trim(str);
  // do with str what you want.
}

I prefer this to adding yet another template parameter for "trimming after 
unquoting".


Original comment by [email protected] on 28 Sep 2014 at 1:55

  • Changed state: Done

from fast-cpp-csv-parser.

Related Issues (9)

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.