DBG: various small improvements
This commit is contained in:
parent
7646747eca
commit
7ab339fa3b
|
|
@ -403,6 +403,7 @@ void pluginloadall(const char* pluginDir)
|
|||
pluginload(StringUtils::Utf16ToUtf8(foundData.cFileName).c_str(), true);
|
||||
}
|
||||
while(FindNextFileW(hSearch, &foundData));
|
||||
CloseHandle(hSearch);
|
||||
SetCurrentDirectoryW(currentDir);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,30 @@
|
|||
#include "stringutils.h"
|
||||
#include "value.h"
|
||||
#include <windows.h>
|
||||
#include <cstdint>
|
||||
|
||||
static inline bool convertLongLongNumber(const char* str, unsigned long long & result, int radix)
|
||||
{
|
||||
errno = 0;
|
||||
char* end;
|
||||
result = strtoull(str, &end, radix);
|
||||
if(!result && end == str)
|
||||
return false;
|
||||
if(result == ULLONG_MAX && errno)
|
||||
return false;
|
||||
if(*end)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool convertNumber(const char* str, size_t & result, int radix)
|
||||
{
|
||||
unsigned long long llr;
|
||||
if(!convertLongLongNumber(str, llr, radix))
|
||||
return false;
|
||||
result = size_t(llr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void StringUtils::Split(const String & s, char delim, std::vector<String> & elems)
|
||||
{
|
||||
elems.clear();
|
||||
|
|
@ -361,17 +383,11 @@ void StringUtils::ReplaceAll(WString & s, const WString & from, const WString &
|
|||
}
|
||||
}
|
||||
|
||||
String StringUtils::sprintf(_Printf_format_string_ const char* format, ...)
|
||||
String StringUtils::vsprintf(const char* format, va_list args)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
char sbuffer[64] = "";
|
||||
if(_vsnprintf_s(sbuffer, _TRUNCATE, format, args) != -1)
|
||||
{
|
||||
va_end(args);
|
||||
return sbuffer;
|
||||
}
|
||||
|
||||
std::vector<char> buffer(256, '\0');
|
||||
while(true)
|
||||
|
|
@ -385,21 +401,23 @@ String StringUtils::sprintf(_Printf_format_string_ const char* format, ...)
|
|||
else
|
||||
break;
|
||||
}
|
||||
va_end(args);
|
||||
return String(buffer.data());
|
||||
}
|
||||
|
||||
WString StringUtils::sprintf(_Printf_format_string_ const wchar_t* format, ...)
|
||||
String StringUtils::sprintf(_Printf_format_string_ const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
auto result = vsprintf(format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
WString StringUtils::vsprintf(const wchar_t* format, va_list args)
|
||||
{
|
||||
wchar_t sbuffer[64] = L"";
|
||||
if(_vsnwprintf_s(sbuffer, _TRUNCATE, format, args) != -1)
|
||||
{
|
||||
va_end(args);
|
||||
return sbuffer;
|
||||
}
|
||||
|
||||
std::vector<wchar_t> buffer(256, L'\0');
|
||||
while(true)
|
||||
|
|
@ -413,10 +431,18 @@ WString StringUtils::sprintf(_Printf_format_string_ const wchar_t* format, ...)
|
|||
else
|
||||
break;
|
||||
}
|
||||
va_end(args);
|
||||
return WString(buffer.data());
|
||||
}
|
||||
|
||||
WString StringUtils::sprintf(_Printf_format_string_ const wchar_t* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
auto result = vsprintf(format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
String StringUtils::ToLower(const String & s)
|
||||
{
|
||||
auto result = s;
|
||||
|
|
@ -548,7 +574,7 @@ bool StringUtils::FromCompressedHex(const String & text, std::vector<unsigned ch
|
|||
}
|
||||
i++; //eat '}'
|
||||
|
||||
duint repeat = 0;
|
||||
size_t repeat = 0;
|
||||
if(!convertNumber(repeatStr.c_str(), repeat, 16) || !repeat) //conversion failed or repeat zero times
|
||||
return false;
|
||||
for(size_t j = 1; j < repeat; j++)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ public:
|
|||
static WString LocalCpToUtf16(const char* wstr);
|
||||
static void ReplaceAll(String & s, const String & from, const String & to);
|
||||
static void ReplaceAll(WString & s, const WString & from, const WString & to);
|
||||
static String vsprintf(_In_z_ _Printf_format_string_ const char* format, va_list args);
|
||||
static String sprintf(_In_z_ _Printf_format_string_ const char* format, ...);
|
||||
static WString vsprintf(_In_z_ _Printf_format_string_ const wchar_t* format, va_list args);
|
||||
static WString sprintf(_In_z_ _Printf_format_string_ const wchar_t* format, ...);
|
||||
static String ToLower(const String & s);
|
||||
static bool StartsWith(const String & h, const String & n);
|
||||
|
|
|
|||
Loading…
Reference in New Issue