Toward core module compiling.
This commit is contained in:
parent
c25a56ee19
commit
3ed195d7dd
305 changed files with 1774 additions and 1065 deletions
|
@ -1,32 +1,32 @@
|
|||
#include "ByteUtils.h"
|
||||
|
||||
|
||||
bool ByteUtils::MostSignificantBitIsOne(char c)
|
||||
bool ByteUtils::MostSignificantBitIsOne(Byte c)
|
||||
{
|
||||
return c & (1 << 7);
|
||||
}
|
||||
|
||||
ByteUtils::Word ByteUtils::GetWordFirstBit(const Word word)
|
||||
Word ByteUtils::GetWordFirstBit(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_FIRST_BIT;
|
||||
};
|
||||
|
||||
ByteUtils::Word ByteUtils::GetWordLastByte(const Word word)
|
||||
Word ByteUtils::GetWordLastByte(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_LAST_BYTE;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getHigherNBits(unsigned char input, unsigned num)
|
||||
unsigned char ByteUtils::getHigherNBits(Byte input, size_t num)
|
||||
{
|
||||
return input >> (8 - num);
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getByteN(uint32_t input, unsigned n)
|
||||
unsigned char ByteUtils::getByteN(DWord input, size_t n)
|
||||
{
|
||||
return (input << 8*n) >> 24;
|
||||
}
|
||||
|
||||
uint32_t ByteUtils::mirror(uint32_t byte, unsigned length)
|
||||
uint32_t ByteUtils::mirror(DWord byte, size_t length)
|
||||
{
|
||||
uint32_t ret{0};
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
|
@ -39,7 +39,7 @@ uint32_t ByteUtils::mirror(uint32_t byte, unsigned length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getLowerNBits(uint32_t input, unsigned num)
|
||||
unsigned char ByteUtils::getLowerNBits(DWord input, size_t num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
|
@ -64,12 +64,12 @@ unsigned char ByteUtils::getLowerNBits(uint32_t input, unsigned num)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getTwoBitsAtN(unsigned char input, unsigned n)
|
||||
unsigned char ByteUtils::getTwoBitsAtN(Byte input, size_t n)
|
||||
{
|
||||
return (input & (0x03 << n)) >> n;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getMBitsAtN(unsigned char input, unsigned m, unsigned n)
|
||||
unsigned char ByteUtils::getMBitsAtN(Byte input, size_t m, size_t n)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ unsigned char ByteUtils::getMBitsAtN(unsigned char input, unsigned m, unsigned n
|
|||
}
|
||||
}
|
||||
|
||||
bool ByteUtils::getBitN(uint32_t input, unsigned n)
|
||||
bool ByteUtils::getBitN(DWord input, size_t n)
|
||||
{
|
||||
return input & (1 << n);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ unsigned char ByteUtils::getFromString(const String& string)
|
|||
{
|
||||
unsigned char ret{0};
|
||||
|
||||
if (string.length() < 8)
|
||||
if (string.size() < 8)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ unsigned char ByteUtils::getFromString(const String& string)
|
|||
return ret;
|
||||
}
|
||||
|
||||
String ByteUtils::toString(uint32_t input, unsigned length)
|
||||
String ByteUtils::toString(DWord input, size_t length)
|
||||
{
|
||||
String ret;
|
||||
if (length > 8)
|
||||
|
@ -144,7 +144,7 @@ String ByteUtils::toString(uint32_t input, unsigned length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void ByteUtils::ReverseBuffer(char* buffer, char* reverse, unsigned size, unsigned targetSize)
|
||||
void ByteUtils::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize)
|
||||
{
|
||||
for(unsigned idx=0; idx<targetSize; idx++)
|
||||
{
|
||||
|
@ -159,22 +159,22 @@ void ByteUtils::ReverseBuffer(char* buffer, char* reverse, unsigned size, unsign
|
|||
}
|
||||
}
|
||||
|
||||
ByteUtils::Word ByteUtils::ToWord(char* buffer, bool reverse)
|
||||
Word ByteUtils::ToWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<Word>(buffer, reverse);
|
||||
}
|
||||
|
||||
ByteUtils::DWord ByteUtils::ToDWord(char* buffer, bool reverse)
|
||||
DWord ByteUtils::ToDWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<DWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
ByteUtils::QWord ByteUtils::ToQWord(char* buffer, bool reverse)
|
||||
QWord ByteUtils::ToQWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<QWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
bool ByteUtils::Compare(char* buffer, const char* tag, unsigned size)
|
||||
bool ByteUtils::Compare(Byte* buffer, const char* tag, size_t size)
|
||||
{
|
||||
for(unsigned idx=0; idx<size; idx++)
|
||||
{
|
||||
|
@ -186,12 +186,12 @@ bool ByteUtils::Compare(char* buffer, const char* tag, unsigned size)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareDWords(char* buffer, const char* tag)
|
||||
bool ByteUtils::CompareDWords(Byte* buffer, const char* tag)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(DWord));
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareWords(char* buffer, const char* tag)
|
||||
bool ByteUtils::CompareWords(Byte* buffer, const char* tag)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(Word));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "ByteTypes.h"
|
||||
#include "String.h"
|
||||
#include <cstring>
|
||||
|
||||
class ByteUtils
|
||||
{
|
||||
|
@ -13,25 +12,25 @@ public:
|
|||
|
||||
static Word GetWordLastByte(const Word word);
|
||||
|
||||
static Byte getByteN(DWord input, std::size_t n);
|
||||
static Byte getByteN(DWord input, size_t n);
|
||||
|
||||
static Byte getHigherNBits(Byte input, std::size_t num);
|
||||
static Byte getHigherNBits(Byte input, size_t num);
|
||||
|
||||
static Byte getLowerNBits(DWord input, std::size_t num);
|
||||
static Byte getLowerNBits(DWord input, size_t num);
|
||||
|
||||
static Byte getTwoBitsAtN(Byte input, std::size_t n);
|
||||
static Byte getTwoBitsAtN(Byte input, size_t n);
|
||||
|
||||
static Byte getMBitsAtN(Byte input, std::size_t m, std::size_t n);
|
||||
static Byte getMBitsAtN(Byte input, size_t m, size_t n);
|
||||
|
||||
static bool getBitN(DWord input, std::size_t n);
|
||||
static bool getBitN(DWord input, size_t n);
|
||||
|
||||
static Byte getFromString(const String& string);
|
||||
|
||||
static String toString(DWord input, std::size_t length = 8);
|
||||
static String toString(DWord input, size_t length = 8);
|
||||
|
||||
static DWord mirror(DWord input, std::size_t length=0);
|
||||
static DWord mirror(DWord input, size_t length=0);
|
||||
|
||||
static void ReverseBuffer(Byte* buffer, Byte* reverse, std::size_t size, std::size_t targetSize);
|
||||
static void ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize);
|
||||
|
||||
template<typename T>
|
||||
static T ToType(Byte* buffer, bool reverse = true)
|
||||
|
@ -41,11 +40,11 @@ public:
|
|||
{
|
||||
char reversed[sizeof(T)];
|
||||
ReverseBuffer(buffer, reversed, sizeof(T), sizeof(T));
|
||||
std::memcpy(&result, reversed, sizeof(T));
|
||||
//std::memcpy(&result, reversed, sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(&result, buffer, sizeof(T));
|
||||
//std::memcpy(&result, buffer, sizeof(T));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -56,7 +55,7 @@ public:
|
|||
|
||||
static QWord ToQWord(Byte* buffer, bool reverse = true);
|
||||
|
||||
static bool Compare(Byte* buffer, const char* tag, std::size_t size);
|
||||
static bool Compare(Byte* buffer, const char* tag, size_t size);
|
||||
|
||||
static bool CompareDWords(Byte* buffer, const char* tag);
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ bool StringUtils::isWhitespaceOnly(const String& input)
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
||||
size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
||||
{
|
||||
auto found_id = input.find(c);
|
||||
if(found_id == String::npos)
|
||||
|
@ -62,8 +62,8 @@ std::size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::size_t count = 1;
|
||||
for(std::size_t idx=found_id+1; idx<input.size(); idx++)
|
||||
size_t count = 1;
|
||||
for(size_t idx=found_id+1; idx<input.size(); idx++)
|
||||
{
|
||||
if(input[idx] == c)
|
||||
{
|
||||
|
@ -85,9 +85,9 @@ String StringUtils::stripSurroundingWhitepsace(const String& input)
|
|||
return {};
|
||||
}
|
||||
|
||||
std::size_t first_nonspace = 0;
|
||||
std::size_t last_nonspace = input.size() - 1;
|
||||
for (std::size_t idx = 0; idx < input.size(); idx++)
|
||||
size_t first_nonspace = 0;
|
||||
size_t last_nonspace = input.size() - 1;
|
||||
for (size_t idx = 0; idx < input.size(); idx++)
|
||||
{
|
||||
if (!std::isspace(input[idx]))
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ String StringUtils::stripSurroundingWhitepsace(const String& input)
|
|||
return {};
|
||||
}
|
||||
|
||||
for (std::size_t idx = last_nonspace; idx > 0; idx--)
|
||||
for (size_t idx = last_nonspace; idx > 0; idx--)
|
||||
{
|
||||
if (!std::isspace(input[idx]))
|
||||
{
|
||||
|
@ -162,8 +162,8 @@ String StringUtils::stripQuotes(const String& input)
|
|||
{
|
||||
return input;
|
||||
}
|
||||
std::size_t start_index = 0;
|
||||
std::size_t end_index = input.size()-1;
|
||||
size_t start_index = 0;
|
||||
size_t end_index = input.size()-1;
|
||||
if (input[start_index] == '"')
|
||||
{
|
||||
start_index = 1;
|
||||
|
@ -177,7 +177,7 @@ String StringUtils::stripQuotes(const String& input)
|
|||
|
||||
String StringUtils::removeUpTo(const String& input, const String& prefix)
|
||||
{
|
||||
std::size_t found = input.find(prefix);
|
||||
size_t found = input.find(prefix);
|
||||
if (found != String::npos)
|
||||
{
|
||||
return input.substr(found + prefix.size(), input.size()-found);
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
static constexpr char SINGLE_QUOTE = '\'';
|
||||
static constexpr char COLON = ':';
|
||||
|
||||
static std::size_t countFirstConsecutiveHits(const String& input, char c);
|
||||
static size_t countFirstConsecutiveHits(const String& input, char c);
|
||||
|
||||
static bool isAlphaNumeric(char c);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdexcept>
|
||||
#include <cstdint>
|
||||
|
||||
/*
|
||||
String UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
|
||||
{
|
||||
if (input.empty())
|
||||
|
@ -23,7 +24,9 @@ String UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
|
|||
throw std::logic_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
std::wstring UnicodeUtils::utf8ToUtf16WString(const String& input)
|
||||
{
|
||||
if (input.empty())
|
||||
|
@ -40,13 +43,15 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const String& input)
|
|||
throw std::logic_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
||||
{
|
||||
const auto utf_16 = utf8ToUtf16WString(input);
|
||||
//const auto utf_16 = utf8ToUtf16WString(input);
|
||||
|
||||
Vector<uint32_t> output;
|
||||
std::size_t pos = 0;
|
||||
/*
|
||||
size_t pos = 0;
|
||||
while (pos < utf_16.size())
|
||||
{
|
||||
const auto c = utf_16[pos];
|
||||
|
@ -68,6 +73,7 @@ Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
class UnicodeUtils
|
||||
{
|
||||
public:
|
||||
static String utf16ToUtf8String(const std::wstring& input);
|
||||
//static String utf16ToUtf8String(const std::wstring& input);
|
||||
|
||||
static std::wstring utf8ToUtf16WString(const String& input);
|
||||
//static std::wstring utf8ToUtf16WString(const String& input);
|
||||
|
||||
static Vector<uint32_t> utf8ToUtf32(const String& input);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue