Ignore:
Timestamp:
05/06/25 23:04:33 (2 days ago)
Author:
Maciej Komosinski
Message:

Added two helper conversion functions: toDouble(), toUInt()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/Convert.cpp

    r1285 r1339  
    1818
    1919#include <stdio.h>
     20#include <stdlib.h>
    2021#include <locale>
    2122#include <iostream>
     
    2526
    2627int Convert::toInt(string s) { return atoi(s.c_str()); }
     28unsigned int Convert::toUInt(string s)
     29{
     30        const char* begin = s.c_str();
     31        char *end;
     32        unsigned int value = strtoul(begin, &end, 10);
     33        return (end == begin) ? 0 : value;
     34}
    2735int Convert::toInt_HexIf0x(string s) { return (s.size() > 2 && s[0] == '0' && s[1] == 'x') ? (int)hexToInt(s.substr(2)) : atoi(s.c_str()); }
    2836float Convert::toFloat(string s) { return (float)atof(s.c_str()); }
     37double Convert::toDouble(string s) { return atof(s.c_str()); }
    2938string Convert::toLowerCase(string s) { std::transform(s.begin(), s.end(), s.begin(), ::tolower);  return s; }
    3039string Convert::toUpperCase(string s) { std::transform(s.begin(), s.end(), s.begin(), ::toupper);  return s; }
Note: See TracChangeset for help on using the changeset viewer.