MCPcopy Create free account
hub / github.com/GJDuck/e9patch / parseEntry

Function parseEntry

src/e9tool/e9csv.cpp:128–185  ·  view source on GitHub ↗

* Parse a CSV entry. */

Source from the content-addressed store, hash-verified

126 * Parse a CSV entry.
127 */
128static bool parseEntry(CSV &csv, MatchVal &val)
129{
130 std::string entry;
131 char c = getChar(csv);
132 switch (c)
133 {
134 case EOF:
135 return false;
136 case '\r': case '\n': case ',':
137 val = MatchVal();
138 unGetChar(c, csv);
139 return true;
140 case '\"':
141 while (true)
142 {
143 c = getChar(csv);
144 switch (c)
145 {
146 case EOF:
147 error("failed to parse CSV file \"%s\" at line %u; "
148 "unexpected end-of-file", csv.filename,
149 csv.lineno);
150 case '\"':
151 c = getChar(csv);
152 if (c != '\"')
153 {
154 unGetChar(c, csv);
155 val = MatchVal(strDup(entry.c_str()));
156 return true;
157 }
158 break;
159 }
160 entry += c;
161 }
162 default:
163 entry += c;
164 while (true)
165 {
166 c = getChar(csv);
167 switch (c)
168 {
169 case ',': case '\n': case '\r': case EOF:
170 {
171 unGetChar(c, csv);
172 intptr_t x;
173 if (entryToInt(entry.c_str(), &x))
174 val = MatchVal(x);
175 else
176 val = MatchVal(strDup(entry.c_str()));
177 return true;
178 }
179 default:
180 entry += c;
181 break;
182 }
183 }
184 }
185}

Callers 1

parseRecordFunction · 0.85

Calls 6

getCharFunction · 0.85
MatchValClass · 0.85
unGetCharFunction · 0.85
errorFunction · 0.85
strDupFunction · 0.85
entryToIntFunction · 0.85

Tested by

no test coverage detected