Do bulk replace of stl types.
This commit is contained in:
parent
521486be62
commit
c25a56ee19
531 changed files with 2274 additions and 2181 deletions
|
@ -99,7 +99,7 @@ bool ByteUtils::getBitN(uint32_t input, unsigned n)
|
|||
return input & (1 << n);
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getFromString(const std::string& string)
|
||||
unsigned char ByteUtils::getFromString(const String& string)
|
||||
{
|
||||
unsigned char ret{0};
|
||||
|
||||
|
@ -118,9 +118,9 @@ unsigned char ByteUtils::getFromString(const std::string& string)
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string ByteUtils::toString(uint32_t input, unsigned length)
|
||||
String ByteUtils::toString(uint32_t input, unsigned length)
|
||||
{
|
||||
std::string ret;
|
||||
String ret;
|
||||
if (length > 8)
|
||||
{
|
||||
unsigned overshoot = length - 8;
|
||||
|
|
|
@ -20,28 +20,28 @@ bool StringUtils::isAlphabetical(char c)
|
|||
return std::isalpha(c);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> StringUtils::toBytes(const std::string& input)
|
||||
Vector<unsigned char> StringUtils::toBytes(const String& input)
|
||||
{
|
||||
return {input.begin(), input.end()};
|
||||
}
|
||||
|
||||
std::string StringUtils::toString(const std::vector<unsigned char>& bytes)
|
||||
String StringUtils::toString(const Vector<unsigned char>& bytes)
|
||||
{
|
||||
return {bytes.begin(), bytes.end()};
|
||||
}
|
||||
|
||||
std::vector<std::string> StringUtils::toLines(const std::string& input)
|
||||
Vector<String> StringUtils::toLines(const String& input)
|
||||
{
|
||||
auto result = std::vector<std::string>{};
|
||||
auto ss = std::stringstream{input};
|
||||
for (std::string line; std::getline(ss, line, '\n');)
|
||||
auto result = Vector<String>{};
|
||||
auto ss = Stringstream{input};
|
||||
for (String line; std::getline(ss, line, '\n');)
|
||||
{
|
||||
result.push_back(line);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool StringUtils::isWhitespaceOnly(const std::string& input)
|
||||
bool StringUtils::isWhitespaceOnly(const String& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
|
@ -53,10 +53,10 @@ bool StringUtils::isWhitespaceOnly(const std::string& input)
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t StringUtils::countFirstConsecutiveHits(const std::string& input, char c)
|
||||
std::size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
||||
{
|
||||
auto found_id = input.find(c);
|
||||
if(found_id == std::string::npos)
|
||||
if(found_id == String::npos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ std::size_t StringUtils::countFirstConsecutiveHits(const std::string& input, cha
|
|||
}
|
||||
}
|
||||
|
||||
std::string StringUtils::stripSurroundingWhitepsace(const std::string& input)
|
||||
String StringUtils::stripSurroundingWhitepsace(const String& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
|
@ -112,10 +112,10 @@ std::string StringUtils::stripSurroundingWhitepsace(const std::string& input)
|
|||
return input.substr(first_nonspace, last_nonspace-first_nonspace + 1);
|
||||
}
|
||||
|
||||
std::vector<std::string> StringUtils::split(const std::string& input)
|
||||
Vector<String> StringUtils::split(const String& input)
|
||||
{
|
||||
std::vector<std::string> substrings;
|
||||
std::string working_string;
|
||||
Vector<String> substrings;
|
||||
String working_string;
|
||||
std::locale loc;
|
||||
bool last_was_nonspace{ false };
|
||||
for (auto c : input)
|
||||
|
@ -142,21 +142,21 @@ std::vector<std::string> StringUtils::split(const std::string& input)
|
|||
return substrings;
|
||||
}
|
||||
|
||||
std::string StringUtils::toLower(const std::string& s)
|
||||
String StringUtils::toLower(const String& s)
|
||||
{
|
||||
std::string ret;
|
||||
String ret;
|
||||
std::transform(s.begin(), s.end(), ret.begin(), [](unsigned char c){ return std::tolower(c); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string StringUtils::toPaddedString(unsigned numBytes, unsigned entry)
|
||||
String StringUtils::toPaddedString(unsigned numBytes, unsigned entry)
|
||||
{
|
||||
std::stringstream sstr;
|
||||
Stringstream sstr;
|
||||
sstr << std::setfill('0') << std::setw(numBytes) << entry;
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
std::string StringUtils::stripQuotes(const std::string& input)
|
||||
String StringUtils::stripQuotes(const String& input)
|
||||
{
|
||||
if (input.size() < 3)
|
||||
{
|
||||
|
@ -175,10 +175,10 @@ std::string StringUtils::stripQuotes(const std::string& input)
|
|||
return input.substr(start_index, end_index - start_index + 1);
|
||||
}
|
||||
|
||||
std::string StringUtils::removeUpTo(const std::string& input, const std::string& prefix)
|
||||
String StringUtils::removeUpTo(const String& input, const String& prefix)
|
||||
{
|
||||
std::size_t found = input.find(prefix);
|
||||
if (found != std::string::npos)
|
||||
if (found != String::npos)
|
||||
{
|
||||
return input.substr(found + prefix.size(), input.size()-found);
|
||||
}
|
||||
|
@ -188,12 +188,12 @@ std::string StringUtils::removeUpTo(const std::string& input, const std::string&
|
|||
}
|
||||
}
|
||||
|
||||
bool StringUtils::startsWith(const std::string& input, const std::string& prefix, bool ignoreWhitespace)
|
||||
bool StringUtils::startsWith(const String& input, const String& prefix, bool ignoreWhitespace)
|
||||
{
|
||||
if(ignoreWhitespace)
|
||||
{
|
||||
const auto loc = input.find(prefix);
|
||||
if (loc == std::string::npos)
|
||||
if (loc == String::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include "ByteTypes.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "String.h"
|
||||
#include "Vector.h"
|
||||
|
||||
class StringUtils
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public:
|
|||
static constexpr char SINGLE_QUOTE = '\'';
|
||||
static constexpr char COLON = ':';
|
||||
|
||||
static std::size_t countFirstConsecutiveHits(const std::string& input, char c);
|
||||
static std::size_t countFirstConsecutiveHits(const String& input, char c);
|
||||
|
||||
static bool isAlphaNumeric(char c);
|
||||
|
||||
|
@ -26,25 +26,25 @@ public:
|
|||
|
||||
static bool isSpace(char c);
|
||||
|
||||
static bool isWhitespaceOnly(const std::string& input);
|
||||
static bool isWhitespaceOnly(const String& input);
|
||||
|
||||
static std::string removeUpTo(const std::string& input, const std::string& prefix);
|
||||
static String removeUpTo(const String& input, const String& prefix);
|
||||
|
||||
static std::vector<std::string> split(const std::string& input);
|
||||
static Vector<String> split(const String& input);
|
||||
|
||||
static bool startsWith(const std::string& input, const std::string& prefix, bool ignoreWhitespace = false);
|
||||
static bool startsWith(const String& input, const String& prefix, bool ignoreWhitespace = false);
|
||||
|
||||
static std::string stripSurroundingWhitepsace(const std::string& input);
|
||||
static String stripSurroundingWhitepsace(const String& input);
|
||||
|
||||
static std::string stripQuotes(const std::string& input);
|
||||
static String stripQuotes(const String& input);
|
||||
|
||||
static std::vector<unsigned char> toBytes(const std::string& input);
|
||||
static Vector<unsigned char> toBytes(const String& input);
|
||||
|
||||
static std::string toLower(const std::string& s);
|
||||
static String toLower(const String& s);
|
||||
|
||||
static std::vector<std::string> toLines(const std::string& input);
|
||||
static Vector<String> toLines(const String& input);
|
||||
|
||||
static std::string toPaddedString(unsigned numBytes, unsigned entry);
|
||||
static String toPaddedString(unsigned numBytes, unsigned entry);
|
||||
|
||||
static std::string toString(const std::vector<unsigned char>& bytes);
|
||||
static String toString(const Vector<unsigned char>& bytes);
|
||||
};
|
||||
|
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
#include "Win32BaseIncludes.h"
|
||||
|
||||
#include <vector>
|
||||
#include "Vector.h"
|
||||
#include <stdexcept>
|
||||
#include <cstdint>
|
||||
|
||||
std::string UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
|
||||
String UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
return std::string();
|
||||
return String();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
const auto size = ::WideCharToMultiByte(CP_UTF8, 0, &input[0], static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr);
|
||||
|
||||
std::string result(size, 0);
|
||||
String result(size, 0);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, &input[0], static_cast<int>(input.size()), &result[0], size, nullptr, nullptr);
|
||||
return result;
|
||||
#else
|
||||
|
@ -24,7 +24,7 @@ std::string UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
|
|||
#endif
|
||||
}
|
||||
|
||||
std::wstring UnicodeUtils::utf8ToUtf16WString(const std::string& input)
|
||||
std::wstring UnicodeUtils::utf8ToUtf16WString(const String& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const std::string& input)
|
|||
|
||||
#ifdef _WIN32
|
||||
const auto charsNeeded = ::MultiByteToWideChar(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
|
||||
std::vector<wchar_t> buffer(charsNeeded);
|
||||
Vector<wchar_t> buffer(charsNeeded);
|
||||
const auto charsConverted = ::MultiByteToWideChar(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &buffer[0], static_cast<int>(buffer.size()));
|
||||
return std::wstring(&buffer[0], charsConverted);
|
||||
#else
|
||||
|
@ -41,11 +41,11 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const std::string& input)
|
|||
#endif
|
||||
}
|
||||
|
||||
std::vector<uint32_t> UnicodeUtils::utf8ToUtf32(const std::string& input)
|
||||
Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
||||
{
|
||||
const auto utf_16 = utf8ToUtf16WString(input);
|
||||
|
||||
std::vector<uint32_t> output;
|
||||
Vector<uint32_t> output;
|
||||
std::size_t pos = 0;
|
||||
while (pos < utf_16.size())
|
||||
{
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "String.h"
|
||||
#include "Vector.h"
|
||||
#include <cstdint>
|
||||
|
||||
class UnicodeUtils
|
||||
{
|
||||
public:
|
||||
static std::string utf16ToUtf8String(const std::wstring& input);
|
||||
static String utf16ToUtf8String(const std::wstring& input);
|
||||
|
||||
static std::wstring utf8ToUtf16WString(const std::string& input);
|
||||
static std::wstring utf8ToUtf16WString(const String& input);
|
||||
|
||||
static std::vector<uint32_t> utf8ToUtf32(const std::string& input);
|
||||
static Vector<uint32_t> utf8ToUtf32(const String& input);
|
||||
|
||||
private:
|
||||
static bool isSurrogate(wchar_t c);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue