CSV_line Class Reference

Uses getNextCSV() to scan and store complete CSV lines. More...

#include <CSV_line.h>

List of all members.

Public Member Functions

 CSV_line ()
 Constructor.
 CSV_line (const std::string &str)
 Constructor from string str.
 CSV_line (const char *pz_str, size_t n=0)
 Constructor from pz_str.
 CSV_line (const CSV_line &)
 Copy constructor.
void setData (const std::string &str)
 Scans line str to extract all its CSV fields.
void setData (const char *pz_str, size_t n=0)
 Scans line pz_str to extract all its CSV fields.

Friends

class test_CSV


Detailed Description

Uses getNextCSV() to scan and store complete CSV lines.

Definition at line 36 of file CSV_line.h.


Constructor & Destructor Documentation

CSV_line::CSV_line (  )  [inline]

Constructor.

Definition at line 55 of file CSV_line.h.

CSV_line::CSV_line ( const std::string &  str  )  [inline]

Constructor from string str.

Definition at line 65 of file CSV_line.h.

CSV_line::CSV_line ( const char *  pz_str,
size_t  n = 0 
) [inline]

Constructor from pz_str.

Definition at line 72 of file CSV_line.h.

CSV_line::CSV_line ( const CSV_line  )  [inline]

Copy constructor.

Definition at line 60 of file CSV_line.h.


Member Function Documentation

int CSV_line::setData ( const std::string &  str  ) 

Scans line str to extract all its CSV fields.

  • Stops scanning when a CSV field ends with "\n" (Line Feed).
  • Processes up to str.length() characters in str [ including char(0) ].
  • Misplaced "\n" (Line Feed) characters are interpreted as comma ',' separators.
  • Removes the trailing "\n" (Line Feed) from the last CSV field.
  • Removes the trailing end of line marker "\r\n" from the last CSV field.

    {{ // test::setData()
        CSV_line csv; //  012 3 ...4. .......5.
        //            // [,,a,b,"c,d","e f ""g"\r\n]
        csv.setData( ",,a,b,\"c,d\",\"e f \"\"g\"\r\n" );
        assertTrue( csv[0] == ""        ); // []
        assertTrue( csv[1] == ""        ); // []
        assertTrue( csv[2] == "a"       ); // [a]
        assertTrue( csv[3] == "b"       ); // [b]
        assertTrue( csv[4] == "c,d"     ); // [c,d]
        assertTrue( csv[5] == "e f \"g" ); // [e f "g]
        assertTrue( csv.size() == 6 );
    }}
See also:
test_CSV::test_setData()

Definition at line 23 of file CSV_line.cpp.

int CSV_line::setData ( const char *  pz_str,
size_t  n = 0 
)

Scans line pz_str to extract all its CSV fields.

  • When n <= 0 computes the length with strlen().
  • Processes all the n chars in pz_str [ including char(0) ].
  • Stops scanning when a CSV field ends with "\n" (Line Feed).
  • Misplaced "\n" (Line Feed) characters are interpreted as comma ',' separators.
  • Removes the trailing "\n" (Line Feed) from the last CSV field.
  • Removes the trailing end of line marker "\r\n" from the last CSV field.

    {{ // test::setData()
        CSV_line csv; //  012 3 ...4. .......5.
        //            // [,,a,b,"c,d","e f ""g"\r\n]
        csv.setData( ",,a,b,\"c,d\",\"e f \"\"g\"\r\n" );
        assertTrue( csv[0] == ""        ); // []
        assertTrue( csv[1] == ""        ); // []
        assertTrue( csv[2] == "a"       ); // [a]
        assertTrue( csv[3] == "b"       ); // [b]
        assertTrue( csv[4] == "c,d"     ); // [c,d]
        assertTrue( csv[5] == "e f \"g" ); // [e f "g]
        assertTrue( csv.size() == 6 );
    }}
See also:
test_CSV::test_setData()

Definition at line 40 of file CSV_line.cpp.


Friends And Related Function Documentation

friend class test_CSV [friend]

Definition at line 44 of file CSV_line.h.


The documentation for this class was generated from the following files:

Generated on Wed May 27 11:04:47 2009 for CSV: by  doxygen 1.5.8