#pragma once #include using namespace std; #pragma warning(disable:4996) std::string format_string(const char* format, ...); string INT64TOSTR(INT64 val); INT64 STRTOINT64(string &str); BOOL GetIntWithCheck(string &str, int &val); BOOL GetInt64WithCheck(string &str, INT64 &val); int GetInt(string &str); BOOL StrToInt32(const char * str,int *result); bool StrToInt64(const char * str,INT64 *result); string ConvUcharToU8(wstring &uniStr); wstring GetWcharFromChar(const char *pChar); template bool StrToIntT(const char * str,Type *result) { Type value = 0; Type sign = 1; Type radix; if (str == NULL) { return false; } if (strlen(str) == 0) { return false; } if (*str == '-') { sign = -1; str++; } if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X')) { radix = 16; str += 2; } //else if(*str == '0') //{ // radix = 8; // str++; //} else { bool HitF = false; size_t Len = strlen(str); for (size_t i = 0; i < Len; i++) { if (str[i] >= '0' && str[i] <= '9') { continue; } HitF = true; break; } if (HitF) { radix = 16; } else { radix = 10; } } while (*str) { if (radix == 16) { if (*str >= '0' && *str <= '9') { value = value * radix + *str - '0'; } else { if ((*str | 0x20) >= 'a' && (*str | 0x20) <= 'f') { value = value * radix + (*str | 0x20) - 'a' + 10; } else { return false; } } } else { value = value * radix + *str - '0'; } str++; } *result = sign*value; return true; }; template bool GetIntWithCheckT(wstring &str, Type &val ) { BYTE *szSrc = new BYTE[str.size() * sizeof(WCHAR) + sizeof(WCHAR)]; wcscpy((wchar_t *)szSrc, str.c_str()); char *szBuf = NULL; DWORD dwNum = WideCharToMultiByte(CP_OEMCP, NULL, (LPCWSTR)szSrc, -1, NULL,0, NULL, FALSE); szBuf = new char[dwNum]; WideCharToMultiByte(CP_OEMCP, NULL, (LPCWSTR)szSrc, -1, szBuf, dwNum, NULL, FALSE); Type nReturn = 0; if(StrToIntT(szBuf,&nReturn) == FALSE) { return false; } if (szSrc != NULL) { delete [] szSrc; szSrc = NULL; } if (szBuf != NULL) { delete [] szBuf; szBuf = NULL; } val = nReturn; return true; }; template bool GetIntWithCheckT1(string &str, Type &val) { Type nReturn = 0; if (StrToIntT(str.c_str(), &nReturn) == FALSE) { return false; } val = nReturn; return true; };