Skip to content

Commit 9e844fd

Browse files
author
Giloo
committed
1 parent f2bdf27 commit 9e844fd

File tree

1 file changed

+17
-89
lines changed

1 file changed

+17
-89
lines changed

src/read.cpp

+17-89
Original file line numberDiff line numberDiff line change
@@ -29,131 +29,59 @@
2929
#include "dinterpreter.hpp"
3030
#include "gdlfpexceptions.hpp"
3131

32-
//#include "format.g"
33-
3432
#if defined(_WIN32) && !defined(__CYGWIN__)
3533
#include <io.h>
3634
#define isatty _isatty
3735
#endif
3836

39-
std::stringstream accept_comma_and_complex_default_format(std::stringstream & is, BaseGDL* parIn) {
40-
if (parIn->Type() == GDL_STRING) return std::stringstream(is.str());
41-
37+
std::stringstream accept_comma_and_complex_default_format(std::stringstream & is) {
4238
bool debug = false;
43-
if (debug) std::cout << "the raw full input :" << is.str() << std::endl;
44-
45-
// for Complex, compting cases is complex since (12) eq (12,12) eq 12 ... count 1
46-
int flag_cplx = 0;
47-
if ((parIn->Type() == GDL_COMPLEX) || (parIn->Type() == GDL_COMPLEXDBL)) flag_cplx = 1;
48-
// int open_brace=0;
49-
//int loop=0;
50-
5139
std::stringstream temp;
5240
char c;
53-
int loop = 0;
54-
int open_brace = 0;
55-
//repeat as many elements necessary, but no more!
56-
//for (SizeT ielem=0; ielem < (*par)->N_Elements(); ++ielem ) {
57-
if (debug) std::cout << "nb elems : " << parIn->N_Elements() << std::endl;
58-
59-
for (int ielem = 0; ielem < parIn->N_Elements(); ++ielem) {
60-
61-
loop++;
6241
while (is.get(c)) { //remove starting blanks, commas, tabs, newlines
63-
if (c == '(') open_brace++;
64-
if (c == ')') open_brace--;
6542
if (c != ',' && c != ' ' && c != '\t' && c != '\n') {
6643
temp.put(c);
6744
break;
6845
}
6946
}
7047
if (debug) std::cout << "after first while : " << temp.str() << std::endl;
7148

72-
while (is.get(c)) { //copy until new separator appears.
73-
if (c != ',' && c != ' ' && c != '\t' && c != '\n') {
74-
if (c == '(') open_brace++;
75-
if (c == ')') open_brace--;
49+
while (is.get(c)) { //copy until new separator appears or we encounter end of line
50+
if (c == '\n'){
7651
temp.put(c);
77-
} else {
78-
is.unget();
7952
break;
53+
} else if (c != ',' && c != ' ' && c != '\t') {
54+
temp.put(c);
55+
} else {
56+
temp.put(32);
8057
}
8158
}
82-
if (debug) std::cout << "after second while : " << temp.str() << std::endl;
83-
if (flag_cplx && (open_brace > 0)) ielem--;
84-
if (debug) std::cout << "ielem : " << ielem << std::endl;
85-
86-
// if ((ielem > 10) || (ielem < -10)) break;
87-
88-
temp.put(' '); //put a spearator between values
89-
90-
// this is a security if the input is really badly formatted
91-
if (loop > 5 * parIn->N_Elements()) break;
92-
93-
} // for loop
94-
95-
// the way to output the content of "temp" :
9659
if (debug) std::cout << "what is transmitted to processing : " << temp.str() << std::endl;
97-
// cout << "what remaind to be processed : " << is.str() << endl;
9860

9961
return temp;
10062
}
101-
std::stringstream accept_comma_and_complex_default_format(std::istream *is, BaseGDL* parIn) {
102-
assert (parIn->Type() != GDL_STRING);
103-
63+
std::stringstream accept_comma_and_complex_default_format(std::istream *is) {
10464
bool debug = false;
105-
106-
// for Complex, compting cases is complex since (12) eq (12,12) eq 12 ... count 1
107-
int flag_cplx = 0;
108-
if ((parIn->Type() == GDL_COMPLEX) || (parIn->Type() == GDL_COMPLEXDBL)) flag_cplx = 1;
109-
// int open_brace=0;
110-
//int loop=0;
111-
11265
std::stringstream temp;
11366
char c;
114-
int loop = 0;
115-
int open_brace = 0;
116-
//repeat as many elements necessary, but no more!
117-
//for (SizeT ielem=0; ielem < (*par)->N_Elements(); ++ielem ) {
118-
if (debug) std::cout << "nb elems : " << parIn->N_Elements() << std::endl;
119-
120-
for (int ielem = 0; ielem < parIn->N_Elements(); ++ielem) {
121-
122-
loop++;
12367
while (is->get(c)) { //remove starting blanks, commas, tabs, newlines
124-
if (c == '(') open_brace++;
125-
if (c == ')') open_brace--;
12668
if (c != ',' && c != ' ' && c != '\t' && c != '\n') {
12769
temp.put(c);
12870
break;
12971
}
13072
}
13173
if (debug) std::cout << "after first while : " << temp.str() << std::endl;
13274

133-
while (is->get(c)) { //copy until new separator appears.
134-
if (c != ',' && c != ' ' && c != '\t' && c != '\n') {
135-
if (c == '(') open_brace++;
136-
if (c == ')') open_brace--;
75+
while (is->get(c)) { //copy until new separator appears or we encounter end of line
76+
if (c == '\n'){
13777
temp.put(c);
138-
} else {
139-
is->unget();
14078
break;
79+
} else if (c != ',' && c != ' ' && c != '\t') {
80+
temp.put(c);
81+
} else {
82+
temp.put(32);
14183
}
14284
}
143-
if (debug) std::cout << "after second while : " << temp.str() << std::endl;
144-
if (flag_cplx && (open_brace > 0)) ielem--;
145-
if (debug) std::cout << "ielem : " << ielem << std::endl;
146-
147-
// if ((ielem > 10) || (ielem < -10)) break;
148-
149-
temp.put(' '); //put a spearator between values
150-
151-
// this is a security if the input is really badly formatted
152-
if (loop > 5 * parIn->N_Elements()) break;
153-
154-
} // for loop
155-
156-
// the way to output the content of "temp" :
15785
if (debug) std::cout << "what is transmitted to processing : " << temp.str() << std::endl;
15886

15987
return temp;
@@ -370,7 +298,7 @@ void read_is(istream* is, EnvT* e, int parOffset) {
370298

371299
stringstream iss(line + "\n");
372300
if (parIn->Type() != GDL_STRING) { //special treatment for decoding commas
373-
std::stringstream temp=accept_comma_and_complex_default_format(iss,parIn);
301+
std::stringstream temp=accept_comma_and_complex_default_format(iss);
374302
parIn->FromStream(temp);
375303
} else { //so much simpler
376304
parIn->FromStream(iss);
@@ -384,7 +312,7 @@ void read_is(istream* is, EnvT* e, int parOffset) {
384312
{
385313

386314
if (parIn->Type() != GDL_STRING) { //special treatment for decoding commas
387-
std::stringstream temp=accept_comma_and_complex_default_format(is,parIn);
315+
std::stringstream temp=accept_comma_and_complex_default_format(is);
388316
parIn->FromStream(temp);
389317
} else { //so much simpler
390318
parIn->FromStream(*is);
@@ -464,7 +392,7 @@ void read_is(istream* is, EnvT* e, int parOffset) {
464392
}
465393

466394
if (parIn->Type() != GDL_STRING) { //special treatment for decoding commas
467-
std::stringstream temp=accept_comma_and_complex_default_format(is,parIn);
395+
std::stringstream temp=accept_comma_and_complex_default_format(is);
468396
parIn->FromStream(temp);
469397
} else { //so much simpler
470398
parIn->FromStream(is);

0 commit comments

Comments
 (0)