00001 // CSV_line.h (C) 2008 adolfo@di-mare.com 00002 00003 #ifdef English_dox 00004 /// Doxygen English documentation. 00005 #define English_dox "Doxygen English documentation" 00006 /// \def English_dox ///< Marks English documentation blocks. 00007 #endif 00008 00009 #ifdef English_dox 00010 /** \file CSV_line.h 00011 \brief C++ wrapper class for \c CSV.h. 00012 00013 \author Adolfo Di Mare <adolfo@di-mare.com> 00014 \date 2008 00015 */ 00016 #endif 00017 00018 #ifdef English_dox 00019 /// \def CSV_line_h ///< Avoids multiple inclusion. 00020 #endif 00021 00022 #ifndef CSV_line_h 00023 #define CSV_line_h 00024 00025 #include "CSV.h" 00026 00027 // CSV: Comma Separated Values [IETF RFC-4180]. 00028 // namespace csv { 00029 00030 #ifdef English_dox 00031 /// Uses \c getNextCSV() to scan and store complete CSV lines. 00032 /// - Oftentimes it helps a lot to \c chop() out trailing CR+LF's. 00033 /// - This class is derived from std::vector<std::string> and has 00034 /// all vector operations and interfaces. 00035 #endif 00036 class CSV_line : public std::vector<std::string> { 00037 public: 00038 CSV_line(); 00039 CSV_line( const std::string & str ); 00040 CSV_line( const char *pz_str , size_t n=0 ); 00041 CSV_line( const CSV_line & ); 00042 void setData( const std::string & str ); 00043 void setData( const char *pz_str , size_t n=0 ); 00044 friend class test_CSV; 00045 }; 00046 00047 #ifdef English_dox 00048 /// \class test_CSV; 00049 /// \brief Tests cases for \c CSV_line. 00050 #endif 00051 00052 #ifdef English_dox 00053 /// Constructor. 00054 #endif 00055 inline CSV_line::CSV_line() { } 00056 00057 #ifdef English_dox 00058 /// Copy constructor. 00059 #endif 00060 inline CSV_line::CSV_line( const CSV_line & ) { } 00061 00062 #ifdef English_dox 00063 /// Constructor from string \c str. 00064 #endif 00065 inline CSV_line::CSV_line( const std::string & str ) { 00066 setData( str ); 00067 } 00068 00069 #ifdef English_dox 00070 /// Constructor from \c pz_str. 00071 #endif 00072 inline CSV_line::CSV_line( const char *pz_str , size_t n ) { 00073 setData( pz_str , n ); 00074 } 00075 00076 #ifdef English_dox 00077 /** \fn int CSV_line::setData( const std::string & str ); 00078 \brief Scans line \c str to extract all its CSV fields. 00079 - Stops scanning when a CSV field ends with \c "\n" (Line Feed). 00080 - Processes up to \c str.length() characters in \c str [ including \c char(0) ]. 00081 - Misplaced \c "\n" (Line Feed) characters are interpreted as comma 00082 \c ',' separators. 00083 - Removes the trailing \c "\n" (Line Feed) from the last CSV field. 00084 - Removes the trailing end of line marker \c "\r\n" from the last CSV field. 00085 00086 \dontinclude test_CSV.cpp 00087 \skipline test::setData() 00088 \until }} 00089 \see test_CSV::test_setData() 00090 */ 00091 #endif 00092 00093 #ifdef English_dox 00094 /** \fn int CSV_line::setData( const char *pz_str , size_t n ); 00095 \brief Scans line \c pz_str to extract all its CSV fields. 00096 - When <code> n <= 0 </code> computes the length with \c strlen(). 00097 - Processes all the \c n chars in \c pz_str [ including \c char(0) ]. 00098 - Stops scanning when a CSV field ends with \c "\n" (Line Feed). 00099 - Misplaced \c "\n" (Line Feed) characters are interpreted as comma 00100 \c ',' separators. 00101 - Removes the trailing \c "\n" (Line Feed) from the last CSV field. 00102 - Removes the trailing end of line marker \c "\r\n" from the last CSV field. 00103 00104 \dontinclude test_CSV.cpp 00105 \skipline test::setData() 00106 \until }} 00107 \see test_CSV::test_setData() 00108 */ 00109 #endif 00110 00111 // }; // namespace csv 00112 00113 #ifdef English_dox 00114 /// Defined by the C++ standard library 00115 namespace std { } // trick to include it into the Doxygen documentation 00116 #endif 00117 00118 #endif 00119 00120 // EOF: CSV_line.h