33 std::string
uReplaceChar(
const std::string & str,
char before,
char after)
35 std::string result = str;
36 for(
unsigned int i=0; i<result.size(); ++i)
38 if(result[i] == before)
46 std::string
uReplaceChar(
const std::string & str,
char before,
const std::string & after)
49 for(
unsigned int i=0; i<str.size(); ++i)
51 if(str.at(i) != before)
53 s.push_back(str.at(i));
65 std::string result = str;
66 for(
unsigned int i=0; i<result.size(); ++i)
69 if(result[i] >=
'a' && result[i]<=
'z')
71 result[i] = result[i] -
'a' +
'A';
79 std::string result = str;
80 for(
unsigned int i=0; i<result.size(); ++i)
83 if(result[i] >=
'A' && result[i]<=
'Z')
85 result[i] = result[i] -
'A' +
'a';
108 s << std::setprecision(precision);
118 s << std::setprecision(precision);
135 return atoi(str.c_str());
141 std::istringstream istr(
uReplaceChar(str,
',',
'.').c_str());
142 istr.imbue(std::locale(
"C"));
150 std::istringstream istr(
uReplaceChar(str,
',',
'.').c_str());
151 istr.imbue(std::locale(
"C"));
180 std::vector<unsigned char>
uStr2Bytes(
const std::string & str)
182 std::vector<unsigned char> bytes(str.size()+1);
183 memcpy(bytes.data(), str.data(), str.size());
184 bytes[bytes.size()-1] =
'\0';
188 std::string
uBytes2Str(
const std::vector<unsigned char> & bytes)
192 if(bytes[bytes.size()-1] !=
'\0')
194 std::vector<unsigned char> tmp = bytes;
196 return std::string((
const char *)tmp.data());
198 return std::string((
const char *)bytes.data());
200 return std::string();
203 std::string
uBytes2Hex(
const char * bytes,
unsigned int bytesLen)
206 if(!bytes || bytesLen == 0)
210 const unsigned char * bytes_u = (
const unsigned char*)(bytes);
212 hex.resize(bytesLen*2);
213 char * pHex = &hex[0];
214 const unsigned char * pEnd = (bytes_u + bytesLen);
215 for(
const unsigned char * pChar = bytes_u; pChar != pEnd; ++pChar, pHex += 2)
225 return uHex2Bytes(&hex[0], (
int)hex.length());
230 std::vector<char> bytes;
231 if(!hex || hexLen % 2 || hexLen == 0)
236 unsigned int bytesLen = hexLen / 2;
237 bytes.resize(bytesLen);
238 unsigned char * pBytes = (
unsigned char *)&bytes[0];
239 const unsigned char * pHex = (
const unsigned char *)hex;
241 unsigned char * pEnd = (pBytes + bytesLen);
242 for(
unsigned char * pChar = pBytes; pChar != pEnd; pChar++, pHex += 2)
253 return std::string(&bytes[0], bytes.size());
258 {
'0',
'0'},{
'0',
'1'},{
'0',
'2'},{
'0',
'3'},{
'0',
'4'},{
'0',
'5'},{
'0',
'6'},{
'0',
'7'},{
'0',
'8'},{
'0',
'9'},{
'0',
'A'},{
'0',
'B'},{
'0',
'C'},{
'0',
'D'},{
'0',
'E'},{
'0',
'F'},
259 {
'1',
'0'},{
'1',
'1'},{
'1',
'2'},{
'1',
'3'},{
'1',
'4'},{
'1',
'5'},{
'1',
'6'},{
'1',
'7'},{
'1',
'8'},{
'1',
'9'},{
'1',
'A'},{
'1',
'B'},{
'1',
'C'},{
'1',
'D'},{
'1',
'E'},{
'1',
'F'},
260 {
'2',
'0'},{
'2',
'1'},{
'2',
'2'},{
'2',
'3'},{
'2',
'4'},{
'2',
'5'},{
'2',
'6'},{
'2',
'7'},{
'2',
'8'},{
'2',
'9'},{
'2',
'A'},{
'2',
'B'},{
'2',
'C'},{
'2',
'D'},{
'2',
'E'},{
'2',
'F'},
261 {
'3',
'0'},{
'3',
'1'},{
'3',
'2'},{
'3',
'3'},{
'3',
'4'},{
'3',
'5'},{
'3',
'6'},{
'3',
'7'},{
'3',
'8'},{
'3',
'9'},{
'3',
'A'},{
'3',
'B'},{
'3',
'C'},{
'3',
'D'},{
'3',
'E'},{
'3',
'F'},
262 {
'4',
'0'},{
'4',
'1'},{
'4',
'2'},{
'4',
'3'},{
'4',
'4'},{
'4',
'5'},{
'4',
'6'},{
'4',
'7'},{
'4',
'8'},{
'4',
'9'},{
'4',
'A'},{
'4',
'B'},{
'4',
'C'},{
'4',
'D'},{
'4',
'E'},{
'4',
'F'},
263 {
'5',
'0'},{
'5',
'1'},{
'5',
'2'},{
'5',
'3'},{
'5',
'4'},{
'5',
'5'},{
'5',
'6'},{
'5',
'7'},{
'5',
'8'},{
'5',
'9'},{
'5',
'A'},{
'5',
'B'},{
'5',
'C'},{
'5',
'D'},{
'5',
'E'},{
'5',
'F'},
264 {
'6',
'0'},{
'6',
'1'},{
'6',
'2'},{
'6',
'3'},{
'6',
'4'},{
'6',
'5'},{
'6',
'6'},{
'6',
'7'},{
'6',
'8'},{
'6',
'9'},{
'6',
'A'},{
'6',
'B'},{
'6',
'C'},{
'6',
'D'},{
'6',
'E'},{
'6',
'F'},
265 {
'7',
'0'},{
'7',
'1'},{
'7',
'2'},{
'7',
'3'},{
'7',
'4'},{
'7',
'5'},{
'7',
'6'},{
'7',
'7'},{
'7',
'8'},{
'7',
'9'},{
'7',
'A'},{
'7',
'B'},{
'7',
'C'},{
'7',
'D'},{
'7',
'E'},{
'7',
'F'},
266 {
'8',
'0'},{
'8',
'1'},{
'8',
'2'},{
'8',
'3'},{
'8',
'4'},{
'8',
'5'},{
'8',
'6'},{
'8',
'7'},{
'8',
'8'},{
'8',
'9'},{
'8',
'A'},{
'8',
'B'},{
'8',
'C'},{
'8',
'D'},{
'8',
'E'},{
'8',
'F'},
267 {
'9',
'0'},{
'9',
'1'},{
'9',
'2'},{
'9',
'3'},{
'9',
'4'},{
'9',
'5'},{
'9',
'6'},{
'9',
'7'},{
'9',
'8'},{
'9',
'9'},{
'9',
'A'},{
'9',
'B'},{
'9',
'C'},{
'9',
'D'},{
'9',
'E'},{
'9',
'F'},
268 {
'A',
'0'},{
'A',
'1'},{
'A',
'2'},{
'A',
'3'},{
'A',
'4'},{
'A',
'5'},{
'A',
'6'},{
'A',
'7'},{
'A',
'8'},{
'A',
'9'},{
'A',
'A'},{
'A',
'B'},{
'A',
'C'},{
'A',
'D'},{
'A',
'E'},{
'A',
'F'},
269 {
'B',
'0'},{
'B',
'1'},{
'B',
'2'},{
'B',
'3'},{
'B',
'4'},{
'B',
'5'},{
'B',
'6'},{
'B',
'7'},{
'B',
'8'},{
'B',
'9'},{
'B',
'A'},{
'B',
'B'},{
'B',
'C'},{
'B',
'D'},{
'B',
'E'},{
'B',
'F'},
270 {
'C',
'0'},{
'C',
'1'},{
'C',
'2'},{
'C',
'3'},{
'C',
'4'},{
'C',
'5'},{
'C',
'6'},{
'C',
'7'},{
'C',
'8'},{
'C',
'9'},{
'C',
'A'},{
'C',
'B'},{
'C',
'C'},{
'C',
'D'},{
'C',
'E'},{
'C',
'F'},
271 {
'D',
'0'},{
'D',
'1'},{
'D',
'2'},{
'D',
'3'},{
'D',
'4'},{
'D',
'5'},{
'D',
'6'},{
'D',
'7'},{
'D',
'8'},{
'D',
'9'},{
'D',
'A'},{
'D',
'B'},{
'D',
'C'},{
'D',
'D'},{
'D',
'E'},{
'D',
'F'},
272 {
'E',
'0'},{
'E',
'1'},{
'E',
'2'},{
'E',
'3'},{
'E',
'4'},{
'E',
'5'},{
'E',
'6'},{
'E',
'7'},{
'E',
'8'},{
'E',
'9'},{
'E',
'A'},{
'E',
'B'},{
'E',
'C'},{
'E',
'D'},{
'E',
'E'},{
'E',
'F'},
273 {
'F',
'0'},{
'F',
'1'},{
'F',
'2'},{
'F',
'3'},{
'F',
'4'},{
'F',
'5'},{
'F',
'6'},{
'F',
'7'},{
'F',
'8'},{
'F',
'9'},{
'F',
'A'},{
'F',
'B'},{
'F',
'C'},{
'F',
'D'},{
'F',
'E'},{
'F',
'F'}
276 unsigned char uHex2Ascii(
const unsigned char & c,
bool rightPart)
322 std::string
uFormatv (
const char *fmt, va_list args)
327 std::vector<char> dynamicbuf(size);
328 char *buf = &dynamicbuf[0];
333 #if defined(_WIN32) && !defined(__MINGW32__) 336 va_copy(argsTmp, args);
341 int needed = vsnprintf_s(buf, size, size, fmt, argsTmp);
343 int needed = vsnprintf (buf, size, fmt, argsTmp);
350 if (needed < (
int)size-1 && needed >= 0) {
352 return std::string (buf, (
size_t) needed);
358 size = needed>=0?needed+2:size*2;
359 dynamicbuf.resize (size);
360 buf = &dynamicbuf[0];
362 return std::string();
369 std::string buf =
uFormatv(fmt, args);
376 wchar_t * createWCharFromChar(
const char * text)
378 DWORD
length = MultiByteToWideChar (CP_ACP, 0, text, -1,
NULL, 0);
379 wchar_t * wText =
new wchar_t[
length];
380 MultiByteToWideChar (CP_ACP, 0, text, -1, wText, length );
385 char * createCharFromWChar(
const wchar_t * wText)
388 char * text =
new char[
length];
389 WideCharToMultiByte (CP_ACP, 0, wText, -1, text, length,
NULL,
NULL);
std::string uFormat(const char *fmt,...)
static const char HEX2ASCII[256][2]
std::vector< char > uHex2Bytes(const std::string &hex)
std::string uReplaceChar(const std::string &str, char before, char after)
double uStr2Double(const std::string &str)
std::string uToUpperCase(const std::string &str)
Some conversion functions.
std::string uHex2Str(const std::string &hex)
bool uStrContains(const std::string &string, const std::string &substring)
std::string uBool2Str(bool boolean)
Wrappers of STL for convenient functions.
int uStr2Int(const std::string &str)
std::string uNumber2Str(unsigned int number)
unsigned char uAscii2Hex(const unsigned char &c)
std::string uBytes2Hex(const char *bytes, unsigned int bytesLen)
bool uStr2Bool(const char *str)
float uStr2Float(const std::string &str)
std::string uToLowerCase(const std::string &str)
std::vector< unsigned char > uStr2Bytes(const std::string &str)
GLM_FUNC_DECL genType::value_type length(genType const &x)
std::string uFormatv(const char *fmt, va_list args)
std::string uBytes2Str(const std::vector< unsigned char > &bytes)
unsigned char uHex2Ascii(const unsigned char &c, bool rightPart)