| 306 | |
| 307 | |
| 308 | qcomp parser_parseComplex(string str) { |
| 309 | |
| 310 | if (!parser_isValidComplex(str)) |
| 311 | error_attemptedToParseComplexFromInvalidString(); |
| 312 | |
| 313 | // we are gauranteed to fully match real, imag or comp after prior validation |
| 314 | smatch match; |
| 315 | |
| 316 | // extract and parse components and their signs (excluding imaginary symbol) |
| 317 | if (regex_match(str, match, regexes::real)) |
| 318 | return qcomp(parser_parseReal(match.str(1)), 0); |
| 319 | |
| 320 | if (regex_match(str, match, regexes::imag)) |
| 321 | return qcomp(0, parser_parseReal(match.str(1))); |
| 322 | |
| 323 | if (regex_match(str, match, regexes::comp)) |
| 324 | return qcomp( |
| 325 | parser_parseReal(match.str(1)), |
| 326 | parser_parseReal(match.str(2))); |
| 327 | |
| 328 | // should be unreachable |
| 329 | error_attemptedToParseComplexFromInvalidString(); |
| 330 | return qcomp(0,0); |
| 331 | } |
| 332 | |
| 333 | |
| 334 |
no test coverage detected