00001
00002 Copyright (c) 2001, Lee Patterson & Ant Works Software
00003 http://ssobjects.sourceforge.net
00004
00005 Original source from http://www.codeproject.com/datetime/dateclass.asp
00006 Copyright (c), Richard Stringer
00007
00008 filename : Parseit.h
00009
00010 changes : 24-AUG-2000 Lee Patterson (lee@antws.com)
00011 - Removed MFC code so it will compile under other
00012 platforms.
00013 - Made more functions use const.
00014
00015 notes : Most of the date alogrithms used in this class
00016 can be found at:
00017 http://www.capecod.net/~pbaum/date/date0.htm
00018
00019 *********************************************************************/
00020
00021 #ifndef __PARSEIT_H_
00022 #define __PARSEIT_H_
00023
00024 #ifdef WIN32
00025 # define snprintf _snprintf //make it linux like (NOTE: snprintf in Linux behaives a little different when you exceed the size
00026 #else
00027 typedef const char* LPCSTR;
00028 typedef char* LPSTR;
00029 #endif
00030
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include "linkedlist.h"
00034
00035 namespace ssobjects
00036 {
00037
00039
00041 // this class is just a CString with some assignment and cast operators
00042
00043
00044
00045
00046
00047
00048
00049
00051 class CParseField
00052 {
00053 public:
00054 CParseField() {};
00055 ~CParseField() {};
00056
00057 operator int() { return atoi(TheData);};
00058 operator long() { return atol(TheData);};
00059 operator double() { return atof(TheData);};
00060 operator LPCSTR() { return (LPCSTR) TheData;}; const
00061 CParseField& operator =(LPCSTR s) {strcpy(TheData,s);return *this;};
00062 CParseField& operator =(CParseField& s) {strcpy(TheData,s.TheData);return *this;};
00063
00064
00065 protected:
00066 char TheData[80];
00067 };
00069
00071
00072
00074
00076 class CParseIt
00077 {
00078 private:
00079 CParseIt(const CParseIt&);
00080 CParseIt& operator=(const CParseIt&);
00081
00082 public:
00083 CParseIt(bool Strip=false);
00084 CParseIt(LPCSTR Data,LPCSTR Sep=",",bool Strip=false);
00085 ~CParseIt();
00086
00087
00088
00089 #ifdef WIN32
00090 bool ParseFile(LPCSTR lpzFileName,LPCSTR Sep=",");
00091 #endif
00092
00093 public:
00094
00095 protected:
00096 bool IsSeperator(char s);
00097 #ifdef WIN32
00098 bool LoadFile(LPCSTR lpzFileName);
00099 #endif
00100
00101 public:
00102
00103 int GetNumFields() {return NumFields;};
00104
00105 LPCSTR GetSeperator() {return Seperator;};
00106
00107 void SetSeperator(LPCSTR Sep) {strncpy(Seperator,Sep,9);};
00108
00109 bool Parse();
00110
00111 bool Parse(LPCSTR Data,LPCSTR Sep=",",bool Strip=false);
00112
00113 bool GetField(int nFNum,LPSTR Buff);
00114
00115
00116 CParseField GetField(int n);
00117
00118
00119 public:
00120 void ReSet();
00121
00122 protected:
00123 bool StripQuotes;
00124 char Seperator[10];
00125 int NumFields;
00126 LinkedList<CParseField> TheFields;
00127 LPSTR TheData;
00128 };
00129
00130 };
00131
00132 #endif