Changeset 436


Ignore:
Timestamp:
Dec 15, 2005, 12:28:43 AM (17 years ago)
Author:
Markus Ringnér
Message:

Added support for NaN:s in read_to_int and read_to_double. Added functions to transform strings to lower and upper case, respectively

Location:
trunk/lib/utility
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility/stl_utility.cc

    r420 r436  
    88#include <string>
    99#include <vector>
     10#include <limits>
    1011
    1112namespace theplu {
     
    1920    if (read_to_string(is,vec_str)){
    2021      for (size_t i=0; i<vec_str.size(); i++) {
    21         if (!is_float(vec_str[i])){
     22        if (is_double(vec_str[i])) {
     23          vec.push_back(atof(vec_str[i].c_str()));
     24        }
     25        else if (is_nan(vec_str[i])) {
     26          vec.push_back(std::numeric_limits<double>::quiet_NaN());
     27        }
     28        else {
    2229          // Jari, this should be communicated with as an exception.
    23 //          std::cerr << "Warning: '" << vec_str[i]
    24 //                    << "' is not a number." << std::endl;
     30          //          std::cerr << "Warning: '" << vec_str[i]
     31          //                    << "' is not a number." << std::endl;
    2532        }
    26         else
    27           vec.push_back(atof(vec_str[i].c_str()));
    28       }
     33      }
    2934      return true;
    3035    }
     
    4146    if (read_to_string(is,vec_str)){
    4247      for (size_t i=0; i<vec_str.size(); i++) {
    43         if (!is_int(vec_str[i])){
     48        if (is_int(vec_str[i])) {
     49          vec.push_back(atoi(vec_str[i].c_str()));
     50        }
     51        else if (is_nan(vec_str[i])) {
     52          vec.push_back(std::numeric_limits<int>::quiet_NaN());
     53        }
     54        else {
    4455          // Jari, this should be communicated with as an exception.
    45 //          std::cerr << "Warning: '" << vec_str[i]
    46 //                    << "' is not an integer." << std::endl;
     56          //          std::cerr << "Warning: '" << vec_str[i]
     57          //                    << "' is not an integer." << std::endl;
    4758        }
    48         else
    49           vec.push_back(atoi(vec_str[i].c_str()));
    5059      }
    5160      return true;
     
    7281  }
    7382
    74 
    7583}} // end of namespace utility and namespace thep
    7684
  • trunk/lib/utility/stl_utility.h

    r432 r436  
    5959  /// vector is emptied before the reading starts. Unexpected
    6060  /// characters are currently skipped with a warning message.
     61  /// NaN is supported to be a double (case-insensitive)
    6162  ///
    6263  /// @return false if end of stream
     
    7475  /// vector is emptied before the reading starts. Unexpected
    7576  /// characters are currently skipped with a warning message.
     77  /// NaN is supported to be an int (case-insensitive)
    7678  ///
    7779  /// @return false if end of stream
     
    9395  bool read_to_string(std::istream&, std::vector<std::string>&);
    9496
     97  ///
     98  /// Function converting a string to lower case
     99  ///
     100  inline void to_lower(std::string& s) {
     101    transform(s.begin(),s.end(), s.begin(), tolower);
     102  }
     103
     104
     105  ///
     106  /// Function converting a string to upper case
     107  ///
     108  inline void to_upper(std::string& s) {
     109    transform(s.begin(),s.end(), s.begin(), toupper);
     110  }
     111
    95112
    96113}} // of namespace utility and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.