Skip to content

Commit eabc5e0

Browse files
committed
Add parseInt/parseFloat/parseBoolean free functions
1 parent ae1214e commit eabc5e0

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/Processing.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,9 @@ inline bool toBoolean(const ::std::string& s) { return s=="true"||s=="1"
14171417
inline int toInt(const ::std::string& s) { return ::std::stoi(s); }
14181418
inline float toFloat(const ::std::string& s) { try { return ::std::stof(s); } catch (...) { return 0.0f; } }
14191419
inline char toChar(int v) { return static_cast<char>(v); }
1420+
inline int parseInt(const ::std::string& s) { try { return ::std::stoi(s); } catch(...) { return 0; } }
1421+
inline float parseFloat(const ::std::string& s) { try { return ::std::stof(s); } catch(...) { return 0.f; } }
1422+
inline bool parseBoolean(const ::std::string& s){ return s=="true"||s=="True"||s=="TRUE"||s=="1"; }
14201423
inline ::std::string toUpperCase(::std::string s) { for(auto& c:s) c=::std::toupper((unsigned char)c); return s; }
14211424
inline ::std::string toLowerCase(::std::string s) { for(auto& c:s) c=::std::tolower((unsigned char)c); return s; }
14221425
inline ::std::string trim(const ::std::string& s) {

0 commit comments

Comments
 (0)