MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / parseNumber

Method parseNumber

src/helper.cpp:422–448  ·  view source on GitHub ↗

* Parses the given string and returns an integer or a float. */

Source from the content-addressed store, hash-verified

420 * Parses the given string and returns an integer or a float.
421 */
422Helper::parseNumberStruct Helper::parseNumber(const std::string& s) {
423 size_t myIndex;
424 long long myInteger;
425 long double myFloat;
426 struct parseNumberStruct ret;
427
428 try { // convert to long long
429 myInteger = std::stoll( s, &myIndex );
430 if( myIndex < s.size() ) {
431 throw myInteger;
432 }
433 ret.myType = parseNumberType::INT;
434 ret.myInteger = myInteger;
435 } catch(...) {
436 try { // convert to long double
437 myFloat = std::stold( s, &myIndex );
438 if( myIndex < s.size() ) {
439 throw myFloat;
440 }
441 ret.myType = parseNumberType::FLOAT;
442 ret.myFloat = myFloat;
443 } catch(...) { // use cell as string
444 ret.myType = parseNumberType::NONE;
445 }
446 }
447 return ret;
448}
449
450
451

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected