Skip to content
  • Mark OLESEN's avatar
    ENH: improve consistency in parsing primitives from strings (issue #590) · 41f59b07
    Mark OLESEN authored
    - Any trailing whitespace when parsing from strings or character buffers
      is ignored rather than being treated as an error. This is consistent
      with behaviour when reading from an Istream and with leading whitespace
      being ignored in the underlying atof/atod, strtof/strtod... functions.
    
    - Allow parsing directly from a std::string instead of just from a 'char*'.
      This reflects the C++11 addition of std::stod to complement the C
      functions strtod. This also makes it easier to parse string directly
      without using an IStringStream.
    
    - Two-parameter parsing methods return success/failure.
      Eg,
    
          if (readInt32(str, &int32Val)) ...
    
    - One-parameter parsing methods return the value on success or
      emit a FatalIOError.
      Eg,
    
          const char* buf;
          int32Val = readInt32(buf, &);
    
    - Improved consistency when parsing unsigned ints.
      Use strtoimax and strtoumax throughout.
    
    - Rename readDoubleScalar -> readDouble, readFloatScalar -> readFloat.
      Using the primitive name directly instead of the Foam typedef for
      better consistency with readInt32 etc.
    
    - Clean/improve parseNasScalar.
      Handle normal numbers directly, reduce some operations.
    41f59b07