| 271 | |
| 272 | |
| 273 | bool parser_isValidComplex(string str) { |
| 274 | |
| 275 | // reject str if it doesn't match complex regex |
| 276 | if (!parser_isAnySizedComplex(str)) |
| 277 | return false; |
| 278 | |
| 279 | // we've so far gauranteed str has a valid form, but we must now check |
| 280 | // each included complex component (which we enumerate) is in range of a qreal |
| 281 | sregex_iterator it(str.begin(), str.end(), regexes::real); |
| 282 | sregex_iterator end; |
| 283 | |
| 284 | // valid coeffs contain 1 or 2 reals, never 0, which regex should have caught |
| 285 | if (it == end) |
| 286 | error_attemptedToParseComplexFromInvalidString(); |
| 287 | |
| 288 | // for each of the 1 or 2 components... |
| 289 | for (; it != end; it++) { |
| 290 | |
| 291 | // check component is in-range of qreal via duck-typing |
| 292 | try { |
| 293 | precisionAgnosticStringToFloat(it->str(0)); |
| 294 | } catch (const out_of_range&) { |
| 295 | return false; |
| 296 | |
| 297 | // error if our regex permitted an unparsable component |
| 298 | } catch (const invalid_argument&) { |
| 299 | error_attemptedToParseComplexFromInvalidString(); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // report that each/all detected components of str can form a valid qcomp |
| 304 | return true; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | qcomp parser_parseComplex(string str) { |
no test coverage detected