29
29
#include " dinterpreter.hpp"
30
30
#include " gdlfpexceptions.hpp"
31
31
32
- // #include "format.g"
33
-
34
32
#if defined(_WIN32) && !defined(__CYGWIN__)
35
33
#include < io.h>
36
34
#define isatty _isatty
37
35
#endif
38
36
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) {
42
38
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
-
51
39
std::stringstream temp;
52
40
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++;
62
41
while (is.get (c)) { // remove starting blanks, commas, tabs, newlines
63
- if (c == ' (' ) open_brace++;
64
- if (c == ' )' ) open_brace--;
65
42
if (c != ' ,' && c != ' ' && c != ' \t ' && c != ' \n ' ) {
66
43
temp.put (c);
67
44
break ;
68
45
}
69
46
}
70
47
if (debug) std::cout << " after first while : " << temp.str () << std::endl;
71
48
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 ' ){
76
51
temp.put (c);
77
- } else {
78
- is.unget ();
79
52
break ;
53
+ } else if (c != ' ,' && c != ' ' && c != ' \t ' ) {
54
+ temp.put (c);
55
+ } else {
56
+ temp.put (32 );
80
57
}
81
58
}
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" :
96
59
if (debug) std::cout << " what is transmitted to processing : " << temp.str () << std::endl;
97
- // cout << "what remaind to be processed : " << is.str() << endl;
98
60
99
61
return temp;
100
62
}
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) {
104
64
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
-
112
65
std::stringstream temp;
113
66
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++;
123
67
while (is->get (c)) { // remove starting blanks, commas, tabs, newlines
124
- if (c == ' (' ) open_brace++;
125
- if (c == ' )' ) open_brace--;
126
68
if (c != ' ,' && c != ' ' && c != ' \t ' && c != ' \n ' ) {
127
69
temp.put (c);
128
70
break ;
129
71
}
130
72
}
131
73
if (debug) std::cout << " after first while : " << temp.str () << std::endl;
132
74
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 ' ){
137
77
temp.put (c);
138
- } else {
139
- is->unget ();
140
78
break ;
79
+ } else if (c != ' ,' && c != ' ' && c != ' \t ' ) {
80
+ temp.put (c);
81
+ } else {
82
+ temp.put (32 );
141
83
}
142
84
}
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" :
157
85
if (debug) std::cout << " what is transmitted to processing : " << temp.str () << std::endl;
158
86
159
87
return temp;
@@ -370,7 +298,7 @@ void read_is(istream* is, EnvT* e, int parOffset) {
370
298
371
299
stringstream iss (line + " \n " );
372
300
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);
374
302
parIn->FromStream (temp);
375
303
} else { // so much simpler
376
304
parIn->FromStream (iss);
@@ -384,7 +312,7 @@ void read_is(istream* is, EnvT* e, int parOffset) {
384
312
{
385
313
386
314
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);
388
316
parIn->FromStream (temp);
389
317
} else { // so much simpler
390
318
parIn->FromStream (*is);
@@ -464,7 +392,7 @@ void read_is(istream* is, EnvT* e, int parOffset) {
464
392
}
465
393
466
394
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);
468
396
parIn->FromStream (temp);
469
397
} else { // so much simpler
470
398
parIn->FromStream (is);
0 commit comments