57 for (
int Y=0; Y<YLen; Y++){
58 if (Str==
GetVal(X, Y)){
return Y;}}
64 for (
int Y=0; Y<YLen; Y++){
76 for (
int X=0; X<XLen; X++){
77 if (
GetVal(X, Y).GetTrunc()==FldNm){
89 for (
int Y=0; Y<
GetYLen(); Y++){
102 const PNotify& Notify,
const bool& IsExcelEoln,
103 const int& MxY,
const TIntV& AllowedColNV,
const bool& IsQStr){
108 int X=0;
int Y=0;
int PrevX=-1;
int PrevY=-1;
113 if (IsQStr&&(Ch==
'"')){
117 while ((!SIn->
Eof())&&(Ch!=
'"')){
118 ChA+=Ch; Ch=SIn->
GetCh();}
121 if (Ch==
'"'){ChA+=Ch; Ch=SIn->
GetCh();}
127 while ((!SIn->
Eof())&&(Ch!=
'\t')&&(Ch!=
'\r')&&((Ch!=
'\n')||IsExcelEoln)){
128 ChA+=Ch; Ch=SIn->
GetCh();
132 while ((!SIn->
Eof())&&(Ch!=
',')&&(Ch!=
'\r')&&((Ch!=
'\n')||IsExcelEoln)){
133 ChA+=Ch; Ch=SIn->
GetCh();
137 while ((!SIn->
Eof())&&(Ch!=
';')&&(Ch!=
'\r')&&((Ch!=
'\n')||IsExcelEoln)){
138 ChA+=Ch; Ch=SIn->
GetCh();
142 while ((!SIn->
Eof())&&(Ch!=
'|')&&(Ch!=
'\r')&&((Ch!=
'\n')||IsExcelEoln)){
143 ChA+=Ch; Ch=SIn->
GetCh();
147 while ((!SIn->
Eof())&&(Ch!=
' ')&&(Ch!=
'\r')&&((Ch!=
'\n')||IsExcelEoln)){
148 ChA+=Ch; Ch=SIn->
GetCh();
156 if ((MxY!=-1)&&(Ss->CellStrVV.Len()==MxY)){
break;}
158 int Recs=Ss->CellStrVV.Len();
163 if (AllowedColNV.
Empty()||AllowedColNV.
IsIn(X)){
164 Ss->CellStrVV[Y]->V.Add(ChA);
171 X++; Ch=SIn->
GetCh();
174 X++; Ch=SIn->
GetCh();
177 X++; Ch=SIn->
GetCh();
179 if ((SsFmt==
ssfVBar)&&(Ch==
'|')){
180 X++; Ch=SIn->
GetCh();
183 X++; Ch=SIn->
GetCh();
186 if ((PrevX!=-1)&&(X!=PrevX)){
188 PrevX=X; X=0; Y++; Ch=SIn->
GetCh();
189 if ((Ch==
'\n')&&(!SIn->
Eof())){Ch=SIn->
GetCh();}
193 if ((PrevX!=-1)&&(X!=PrevX)){
195 PrevX=X; X=0; Y++; Ch=SIn->
GetCh();
196 if ((Ch==
'\r')&&(!SIn->
Eof())){Ch=SIn->
GetCh();}
203 int Recs=Ss->CellStrVV.Len();
212 for (
int X=0; X<
CellStrVV[Y]->Len(); X++){
213 if (X>0){SOut->
PutCh(
'\t');}
216 for (
int ChN=0; ChN<ChA.
Len(); ChN++){
218 if ((Ch==
'\t')||(Ch==
'\r')||(Ch==
'\n')){
229 const TSsFmt& SsFmt,
const PSIn& SIn,
char& Ch,
230 TStrV& FldValV,
const bool& IsExcelEoln,
const bool& IsQStr){
232 FldValV.
Clr(
false);
int X=0;
238 if (IsQStr&&(Ch==
'"')){
242 while ((!SIn->
Eof())&&(Ch!=
'"')){
243 ChA+=Ch; Ch=SIn->
GetCh();}
246 if (Ch==
'"'){ChA+=Ch; Ch=SIn->
GetCh();}
252 while ((!SIn->
Eof())&&(Ch!=
'\t')&&(Ch!=
'\r')&&
253 ((Ch!=
'\n')||IsExcelEoln)){
254 ChA+=Ch; Ch=SIn->
GetCh();
260 while ((!SIn->
Eof())&&(Ch!=
',')&&(Ch!=
'\r')&&
261 ((Ch!=
'\n')||IsExcelEoln)){
262 ChA+=Ch; Ch=SIn->
GetCh();
266 while ((!SIn->
Eof())&&(Ch!=
';')&&(Ch!=
'\r')&&
267 ((Ch!=
'\n')||IsExcelEoln)){
268 ChA+=Ch; Ch=SIn->
GetCh();
272 while ((!SIn->
Eof())&&(Ch!=
'|')&&(Ch!=
'\r')&&
273 ((Ch!=
'\n')||IsExcelEoln)){
274 ChA+=Ch; Ch=SIn->
GetCh();
288 X++; Ch=SIn->
GetCh();
291 X++; Ch=SIn->
GetCh();
294 X++; Ch=SIn->
GetCh();
296 if ((SsFmt==
ssfVBar)&&(Ch==
'|')){
297 X++; Ch=SIn->
GetCh();
301 if ((Ch==
'\n')&&(!SIn->
Eof())){Ch=SIn->
GetCh();}
305 X=0; Ch=SIn->
GetCh();
306 if ((Ch==
'\r')&&(!SIn->
Eof())){Ch=SIn->
GetCh();}
320 else if (LcSsFmtNm==
"vbar"){
return ssfVBar;}
334 default:
return "undef";
341 ChA+=
"tab"; ChA+=
", ";
342 ChA+=
"comma"; ChA+=
", ";
343 ChA+=
"semicolon"; ChA+=
", ";
344 ChA+=
"space"; ChA+=
", ";
345 ChA+=
"white"; ChA+=
")";
352 SkipLeadBlanks(_SkipLeadBlanks), SkipCmt(_SkipCmt), SkipEmptyFld(_SkipEmptyFld), LineCnt(0), SplitCh(
'\t'), LineStr(), FldV(), FInPt(NULL) {
363 default:
FailR(
"Unknown separator character.");
368 SkipLeadBlanks(_SkipLeadBlanks), SkipCmt(_SkipCmt), SkipEmptyFld(_SkipEmptyFld), LineCnt(0), SplitCh(
'\t'), LineStr(), FldV(), FInPt(NULL) {
392 while (*cur &&
TCh::IsWs(*cur)) { cur++; }
397 else {
while (*cur && *cur!=
SplitCh) { cur++; } }
398 if (*cur == 0) {
break; }
420 while (*cur &&
TCh::IsWs(*cur)) { cur++; }
425 else {
while (*cur && *cur!=
SplitCh) { cur++; } }
426 if (*cur == 0) {
break; }
437 for (
int f = 0; f <
FldV.
Len(); f++) {
438 for (
char *c =
FldV[f]; *c; c++) {
447 const char *c =
GetFld(FldN);
449 if (*c==
'-') { Minus=
true; c++; }
456 if (Minus) { _Val = -_Val; }
457 if (*c != 0) {
return false; }
464 const char *c =
GetFld(FldN);
466 if (*c==
'+' || *c==
'-') { c++; }
467 if (!
TCh::IsNum(*c) && *c!=
'.') {
return false; }
473 if (*c==
'e' || *c ==
'E') {
475 if (*c ==
'+' || *c ==
'-' ) { c++; }
479 if (*c != 0) {
return false; }
485 static TChA ChA(10*1024);
487 for (
int i = 0; i <
FldV.
Len(); i++) {
TSsFmt SsFmt
Separator type.
int SearchX(const int &Y, const TStr &Str) const
static PSOut New(const TStr &FNm, const bool &Append=false)
static PSs LoadTxt(const TSsFmt &SsFmt, const TStr &FNm, const PNotify &Notify=NULL, const bool &IsExcelEoln=true, const int &MxY=-1, const TIntV &AllowedColNV=TIntV(), const bool &IsQStr=true)
static bool IsNum(const char &Ch)
virtual int PutCh(const char &Ch)=0
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
static int GetMx(const int &Int1, const int &Int2)
void PutCh(const int &ChN, const char &Ch)
bool NextSlow()
Loads next line from the input file (older, slow implementation - deprecated).
TSizeTy Len() const
Returns the number of elements in the vector.
uint64 LineCnt
Number of processed lines so far.
void ToLc()
Transforms the current line to lower case.
TSsParser(const TStr &FNm, const TSsFmt _SsFmt=ssfTabSep, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false)
Constructor.
static TStr GetSsFmtNmVStr()
bool GetInt(const int &FldN, int &Val) const
If the field FldN is an integer its value is returned in Val and the function returns true...
TStr GetVal(const int &X, const int &Y) const
static PSIn New(const TStr &FNm)
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
TSsFmt
Spread-Sheet Separator Format.
bool Empty() const
Tests whether the vector is empty.
void SaveTxt(const TStr &FNm, const PNotify &Notify=NULL) const
TVec< char * > FldV
Pointers to fields of the current line.
static TSsFmt GetSsFmtFromStr(const TStr &SsFmtNm)
static PSIn New(const TStr &FNm)
static bool IsWs(const char &Ch)
TChA LineStr
Current line.
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
int SearchY(const int &X, const TStr &Str) const
const char * DumpStr() const
static int GetNum(const char &Ch)
Whitespace (space or tab) separated.
const TVal & Last() const
Returns a reference to the last element of the vector.
bool GetFlt(const int &FldN, double &Val) const
If the field FldN is a float its value is returned in Val and the function returns true...
virtual void OnNotify(const TNotifyType &, const TStr &)
PSIn FInPt
Pointer to the input file stream.
static bool IsZipExt(const TStr &FNmExt)
Check whether the file extension FNmExt is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
static void LoadTxtFldV(const TSsFmt &SsFmt, const PSIn &SIn, char &Ch, TStrV &FldValV, const bool &IsExcelEoln=true, const bool &IsQStr=true)
virtual void OnStatus(const TStr &)
static TStr Fmt(const char *FmtStr,...)
int PutStr(const char *CStr)
bool SkipCmt
Skip comments (lines starting with #).
bool SkipLeadBlanks
Ignore leading whitespace characters in a line.
bool Next()
Loads next line from the input file.
char SplitCh
Separator character (if one of the non-started separators is used)
static TStr GetStrFromSsFmt(const TSsFmt &SsFmt)
static TPt< PVec< TVal > > New()
TStr & At(const int &X, const int &Y)
virtual bool GetNextLnBf(TChA &LnChA)=0
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
void DelLast()
Removes the last element of the vector.
int GetFldY(const TStr &FldNm, const TStr &NewFldNm="", const int &X=0) const
bool SkipEmptyFld
Skip empty fields (i.e., multiple consecutive separators are considered as one).
int GetFldX(const TStr &FldNm, const TStr &NewFldNm="", const int &Y=0) const
bool GetNextLn(TStr &LnStr)
void PutVal(const int &X, const int &Y, const TStr &Str)