Skip to content

Commit 9348053

Browse files
committed
- fixed redundant space at the end of GetLnStr()
- added test file TestData.zip in tutorials - added reading by field in demo-TSsParser.cpp
1 parent dc31eb7 commit 9348053

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ tutorials/*
5555
!tutorials/Makefile
5656
!tutorials/cncom
5757
!tutorials/graphviz
58+
!tutorials/parser
5859
tutorials/.DS_Store
5960
tutorials/*.dSYM
6061
benchmarking/*.dat

glib-core/ss.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ClassTP(TSsParser, PSsParser)//{
100100
/// Checks for end of file.
101101
bool Eof() const { return FInPt->Eof(); }
102102
/// Returns the current line
103-
TChA GetLnStr() const { TChA LnOut; for (int i = 0; i < Len(); i++) { LnOut+=GetFld(i); LnOut+=' '; } return LnOut; }
103+
TChA GetLnStr() const { TChA LnOut; for (int i = 0; i < Len(); i++) { LnOut+=GetFld(i); LnOut+=' '; } if (LnOut.Len() > 0) LnOut.DelLastCh(); return LnOut; }
104104
/// Transforms the current line to lower case.
105105
void ToLc();
106106

glib-core/ssmp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ClassTP(TSsParserMP, PSsParserMP)//{
3939
/// Checks for end of file.
4040
bool Eof() const { return FInPt->Eof(); }
4141
/// Returns the current line
42-
TChA GetLnStr() const { TChA LnOut; for (int i = 0; i < Len(); i++) { LnOut+=GetFld(i); LnOut+=' '; } return LnOut; }
42+
TChA GetLnStr() const { TChA LnOut; for (int i = 0; i < Len(); i++) { LnOut+=GetFld(i); LnOut+=' '; } if (LnOut.Len() > 0) LnOut.DelLastCh(); return LnOut; }
4343
/// Transforms the current line to lower case.
4444
void ToLc();
4545

tutorials/demo-TSsParser.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
#include "Snap.h"
22

3-
int main(int argc, const char * argv[]) {
4-
TSsParser Ss("TestData3.zip", ssfCommaSep);
3+
//
4+
// short demo code for the TSsParser (spreadsheet parser) class
5+
//
6+
7+
void ReadByField() {
8+
int LnCnt;
9+
10+
TSsParser Ss("parser/TestData.zip", ssfCommaSep);
11+
12+
LnCnt = 0;
13+
while (Ss.Next()) {
14+
LnCnt++;
15+
for (int i = 0; i < Ss.Len(); i++) {
16+
printf("line %2d, field %2d: %s\n", LnCnt, i+1, Ss[i]);
17+
}
18+
}
19+
}
20+
21+
void ReadByLine() {
22+
TSsParser Ss("parser/TestData.zip", ssfCommaSep);
523

624
while (Ss.Next()) {
725
printf("%s\n", Ss.GetLnStr().CStr());
826
}
27+
}
928

29+
int main(int argc, const char * argv[]) {
30+
ReadByField();
31+
ReadByLine();
1032
return 0;
1133
}
1234

tutorials/parser/TestData.zip

683 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)