Changeset 1285 for cpp/common
- Timestamp:
- 12/06/23 03:27:30 (12 months ago)
- Location:
- cpp/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/Convert.cpp
r1274 r1285 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 1Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 18 18 19 19 #include <stdio.h> 20 20 #include <locale> 21 #include <iostream> 22 #ifndef IPHONE 23 #include <codecvt> 24 #endif 21 25 22 26 int Convert::toInt(string s) { return atoi(s.c_str()); } 27 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()); } 23 28 float Convert::toFloat(string s) { return (float)atof(s.c_str()); } 24 29 string Convert::toLowerCase(string s) { std::transform(s.begin(), s.end(), s.begin(), ::tolower); return s; } 25 30 string Convert::toUpperCase(string s) { std::transform(s.begin(), s.end(), s.begin(), ::toupper); return s; } 31 #if !defined IPHONE && !defined MACOS 32 static string transformUTF8(string in, wint_t(*fun)(wint_t)) 33 { 34 static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter; 35 auto wstr = converter.from_bytes(in); 36 for (auto it = wstr.begin(); it != wstr.end(); it++) 37 *it = fun(*it); 38 return converter.to_bytes(wstr); 39 } 40 //does not seem to work in iPhone e.g. for Polish-specific letters, or a different locale settings should be used (but pl-PL did not work properly either) - so instead implemented this using NSString function in objc-interface.mm 41 string Convert::toLowerCaseUTF8(string s) { return transformUTF8(s, towlower); } 42 string Convert::toUpperCaseUTF8(string s) { return transformUTF8(s, towupper); } 43 #endif 26 44 char Convert::toLowerCase(char c) { return (char)tolower(c); } 27 45 char Convert::toUpperCase(char c) { return (char)toupper(c); } -
cpp/common/Convert.h
r1028 r1285 22 22 public: 23 23 static int toInt(string s); 24 static int toInt_HexIf0x(string s); 24 25 static float toFloat(string s); 25 26 static string toLowerCase(string s); 26 27 static string toUpperCase(string s); 28 static string toLowerCaseUTF8(string s); 29 static string toUpperCaseUTF8(string s); 27 30 static char toLowerCase(char c); 28 31 static char toUpperCase(char c);
Note: See TracChangeset
for help on using the changeset viewer.