Changeset 1339
- Timestamp:
- 05/06/25 23:04:33 (2 days ago)
- Location:
- cpp/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/Convert.cpp
r1285 r1339 18 18 19 19 #include <stdio.h> 20 #include <stdlib.h> 20 21 #include <locale> 21 22 #include <iostream> … … 25 26 26 27 int Convert::toInt(string s) { return atoi(s.c_str()); } 28 unsigned 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 } 27 35 int Convert::toInt_HexIf0x(string s) { return (s.size() > 2 && s[0] == '0' && s[1] == 'x') ? (int)hexToInt(s.substr(2)) : atoi(s.c_str()); } 28 36 float Convert::toFloat(string s) { return (float)atof(s.c_str()); } 37 double Convert::toDouble(string s) { return atof(s.c_str()); } 29 38 string Convert::toLowerCase(string s) { std::transform(s.begin(), s.end(), s.begin(), ::tolower); return s; } 30 39 string Convert::toUpperCase(string s) { std::transform(s.begin(), s.end(), s.begin(), ::toupper); return s; } -
cpp/common/Convert.h
r1285 r1339 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2025 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 12 12 #include <cmath> 13 13 14 #ifdef LINUX15 #define UINT64_FORMAT "%llu" //we want to avoid this and ambiguous "long long", but gcc does not seem to support I64u (yet?)16 #else17 #define UINT64_FORMAT "%I64u"18 #endif19 14 20 15 struct Convert … … 22 17 public: 23 18 static int toInt(string s); 19 static unsigned int toUInt(string s); 24 20 static int toInt_HexIf0x(string s); 25 21 static float toFloat(string s); 22 static double toDouble(string s); 26 23 static string toLowerCase(string s); 27 24 static string toUpperCase(string s);
Note: See TracChangeset
for help on using the changeset viewer.