* Parse a CSV entry. */
| 126 | * Parse a CSV entry. |
| 127 | */ |
| 128 | static 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 | } |
no test coverage detected