mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Update utility.cpp
This commit is contained in:
parent
f9ea1b0f65
commit
1662816c5d
@ -297,53 +297,53 @@ string CreateDirectories(string svInput, bool bWindows)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fs::path fspPathOut(svInput);
|
fs::path fspPathOut(svInput);
|
||||||
string results = fspPathOut.u8string();
|
string result = fspPathOut.u8string();
|
||||||
|
|
||||||
fspPathOut = fspPathOut.parent_path();
|
fspPathOut = fspPathOut.parent_path();
|
||||||
fs::create_directories(fspPathOut);
|
fs::create_directories(fspPathOut);
|
||||||
|
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// For converting filepaths to windows filepaths.
|
// For converting filepaths to windows filepaths.
|
||||||
string ConvertToWinPath(const string& svInput)
|
string ConvertToWinPath(const string& svInput)
|
||||||
{
|
{
|
||||||
string results = svInput;
|
string result = svInput;
|
||||||
|
|
||||||
// Flip forward slashes in filepath to windows-style backslash
|
// Flip forward slashes in filepath to windows-style backslash
|
||||||
for (size_t i = 0; i < results.size(); i++)
|
for (size_t i = 0; i < result.size(); i++)
|
||||||
{
|
{
|
||||||
if (results[i] == '/')
|
if (result[i] == '/')
|
||||||
{
|
{
|
||||||
results[i] = '\\';
|
result[i] = '\\';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// For converting filepaths to unix filepaths.
|
// For converting filepaths to unix filepaths.
|
||||||
string ConvertToUnixPath(const string& svInput)
|
string ConvertToUnixPath(const string& svInput)
|
||||||
{
|
{
|
||||||
string results = svInput;
|
string result = svInput;
|
||||||
|
|
||||||
// Flip windows-style backslashes in filepath to forward slash
|
// Flip windows-style backslashes in filepath to forward slash
|
||||||
for (size_t i = 0; i < results.size(); i++)
|
for (size_t i = 0; i < result.size(); i++)
|
||||||
{
|
{
|
||||||
if (results[i] == '\\')
|
if (result[i] == '\\')
|
||||||
{
|
{
|
||||||
results[i] = '/';
|
result[i] = '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// For encoding data in Base64.
|
// For encoding data in Base64.
|
||||||
string Base64Encode(const string& svInput)
|
string Base64Encode(const string& svInput)
|
||||||
{
|
{
|
||||||
string results;
|
string result;
|
||||||
int val = 0, valb = -6;
|
int val = 0, valb = -6;
|
||||||
|
|
||||||
for (unsigned char c : svInput)
|
for (unsigned char c : svInput)
|
||||||
@ -352,26 +352,26 @@ string Base64Encode(const string& svInput)
|
|||||||
valb += 8;
|
valb += 8;
|
||||||
while (valb >= 0)
|
while (valb >= 0)
|
||||||
{
|
{
|
||||||
results.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(val >> valb) & 0x3F]);
|
result.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(val >> valb) & 0x3F]);
|
||||||
valb -= 6;
|
valb -= 6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (valb > -6)
|
if (valb > -6)
|
||||||
{
|
{
|
||||||
results.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[((val << 8) >> (valb + 8)) & 0x3F]);
|
result.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[((val << 8) >> (valb + 8)) & 0x3F]);
|
||||||
}
|
}
|
||||||
while (results.size() % 4)
|
while (result.size() % 4)
|
||||||
{
|
{
|
||||||
results.push_back('=');
|
result.push_back('=');
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// For decoding data in Base64.
|
// For decoding data in Base64.
|
||||||
string Base64Decode(const string& svInput)
|
string Base64Decode(const string& svInput)
|
||||||
{
|
{
|
||||||
string results;
|
string result;
|
||||||
int val = 0, valb = -8;
|
int val = 0, valb = -8;
|
||||||
|
|
||||||
vector<int> T(256, -1);
|
vector<int> T(256, -1);
|
||||||
@ -390,25 +390,25 @@ string Base64Decode(const string& svInput)
|
|||||||
valb += 6;
|
valb += 6;
|
||||||
if (valb >= 0)
|
if (valb >= 0)
|
||||||
{
|
{
|
||||||
results.push_back(char((val >> valb) & 0xFF));
|
result.push_back(char((val >> valb) & 0xFF));
|
||||||
valb -= 8;
|
valb -= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// For encoding data in UTF8.
|
// For encoding data in UTF8.
|
||||||
string UTF8Encode(const wstring& wsvInput)
|
string UTF8Encode(const wstring& wsvInput)
|
||||||
{
|
{
|
||||||
string results;
|
string result;
|
||||||
int nLen = WideCharToMultiByte(CP_UTF8, 0, wsvInput.c_str(), wsvInput.length(), NULL, 0, NULL, NULL);
|
int nLen = WideCharToMultiByte(CP_UTF8, 0, wsvInput.c_str(), wsvInput.length(), NULL, 0, NULL, NULL);
|
||||||
if (nLen > 0)
|
if (nLen > 0)
|
||||||
{
|
{
|
||||||
results.resize(nLen);
|
result.resize(nLen);
|
||||||
WideCharToMultiByte(CP_UTF8, 0, wsvInput.c_str(), wsvInput.length(), &results[0], nLen, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, wsvInput.c_str(), wsvInput.length(), &result[0], nLen, NULL, NULL);
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -494,66 +494,66 @@ bool StringReplace(string& svInput, const string& svFrom, const string& svTo)
|
|||||||
// For replacing parts of a given string by value.
|
// For replacing parts of a given string by value.
|
||||||
string StringReplaceC(const string& svInput, const string& svFrom, const string& svTo)
|
string StringReplaceC(const string& svInput, const string& svFrom, const string& svTo)
|
||||||
{
|
{
|
||||||
string results = svInput;
|
string result = svInput;
|
||||||
string::size_type nPos = results.find(svFrom);
|
string::size_type nPos = result.find(svFrom);
|
||||||
|
|
||||||
if (nPos == string::npos)
|
if (nPos == string::npos)
|
||||||
{
|
{
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
results.replace(nPos, svFrom.length(), svTo);
|
result.replace(nPos, svFrom.length(), svTo);
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// For escaping special characters in a string.
|
// For escaping special characters in a string.
|
||||||
string StringEscape(const string& svInput)
|
string StringEscape(const string& svInput)
|
||||||
{
|
{
|
||||||
string results;
|
string result;
|
||||||
results.reserve(svInput.size());
|
result.reserve(svInput.size());
|
||||||
|
|
||||||
for (const char c : svInput)
|
for (const char c : svInput)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
//case '\'': results += "\\'"; break;
|
//case '\'': result += "\\'"; break;
|
||||||
case '\a': results += "\\a"; break;
|
case '\a': result += "\\a"; break;
|
||||||
case '\b': results += "\\b"; break;
|
case '\b': result += "\\b"; break;
|
||||||
case '\f': results += "\\f"; break;
|
case '\f': result += "\\f"; break;
|
||||||
case '\n': results += "\\n"; break;
|
case '\n': result += "\\n"; break;
|
||||||
case '\r': results += "\\r"; break;
|
case '\r': result += "\\r"; break;
|
||||||
case '\t': results += "\\t"; break;
|
case '\t': result += "\\t"; break;
|
||||||
case '\v': results += "\\v"; break;
|
case '\v': result += "\\v"; break;
|
||||||
default: results += c; break;
|
default: result += c; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// For unescaping special characters in a string.
|
// For unescaping special characters in a string.
|
||||||
string StringUnescape(const string& svInput)
|
string StringUnescape(const string& svInput)
|
||||||
{
|
{
|
||||||
string results;
|
string result;
|
||||||
results.reserve(svInput.size());
|
result.reserve(svInput.size());
|
||||||
|
|
||||||
for (const char c : svInput)
|
for (const char c : svInput)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
//case '\\': results += "\'"; break;
|
//case '\\': result += "\'"; break;
|
||||||
case '\\a': results += "\a"; break;
|
case '\\a': result += "\a"; break;
|
||||||
case '\\b': results += "\b"; break;
|
case '\\b': result += "\b"; break;
|
||||||
case '\\f': results += "\f"; break;
|
case '\\f': result += "\f"; break;
|
||||||
case '\\n': results += "\n"; break;
|
case '\\n': result += "\n"; break;
|
||||||
case '\\r': results += "\r"; break;
|
case '\\r': result += "\r"; break;
|
||||||
case '\\t': results += "\t"; break;
|
case '\\t': result += "\t"; break;
|
||||||
case '\\v': results += "\v"; break;
|
case '\\v': result += "\v"; break;
|
||||||
default: results += c; break;
|
default: result += c; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -732,16 +732,16 @@ void PrintM128i64(__m128i in)
|
|||||||
// For escaping the '%' character for *rintf.
|
// For escaping the '%' character for *rintf.
|
||||||
string PrintPercentageEscape(const string& svInput)
|
string PrintPercentageEscape(const string& svInput)
|
||||||
{
|
{
|
||||||
string results;
|
string result;
|
||||||
results.reserve(svInput.size());
|
result.reserve(svInput.size());
|
||||||
|
|
||||||
for (const char c : svInput)
|
for (const char c : svInput)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '%': results += "%%"; break;
|
case '%': result += "%%"; break;
|
||||||
default: results += c; break;
|
default: result += c; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user