Core lib building
This commit is contained in:
parent
3ed195d7dd
commit
94fcc42aed
73 changed files with 625 additions and 661 deletions
|
@ -1,32 +1,31 @@
|
|||
#include "ByteUtils.h"
|
||||
#include "Bits.h"
|
||||
|
||||
|
||||
bool ByteUtils::MostSignificantBitIsOne(Byte c)
|
||||
bool Bits::MostSignificantBitIsOne(Byte c)
|
||||
{
|
||||
return c & (1 << 7);
|
||||
}
|
||||
|
||||
Word ByteUtils::GetWordFirstBit(const Word word)
|
||||
Word Bits::GetWordFirstBit(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_FIRST_BIT;
|
||||
return word & Bits::WORD_FIRST_BIT;
|
||||
};
|
||||
|
||||
Word ByteUtils::GetWordLastByte(const Word word)
|
||||
Word Bits::GetWordLastByte(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_LAST_BYTE;
|
||||
return word & Bits::WORD_LAST_BYTE;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getHigherNBits(Byte input, size_t num)
|
||||
unsigned char Bits::getHigherNBits(Byte input, size_t num)
|
||||
{
|
||||
return input >> (8 - num);
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getByteN(DWord input, size_t n)
|
||||
unsigned char Bits::getByteN(DWord input, size_t n)
|
||||
{
|
||||
return (input << 8*n) >> 24;
|
||||
}
|
||||
|
||||
uint32_t ByteUtils::mirror(DWord byte, size_t length)
|
||||
uint32_t Bits::mirror(DWord byte, size_t length)
|
||||
{
|
||||
uint32_t ret{0};
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
|
@ -39,7 +38,7 @@ uint32_t ByteUtils::mirror(DWord byte, size_t length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getLowerNBits(DWord input, size_t num)
|
||||
unsigned char Bits::getLowerNBits(DWord input, size_t num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
|
@ -64,12 +63,12 @@ unsigned char ByteUtils::getLowerNBits(DWord input, size_t num)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getTwoBitsAtN(Byte input, size_t n)
|
||||
unsigned char Bits::getTwoBitsAtN(Byte input, size_t n)
|
||||
{
|
||||
return (input & (0x03 << n)) >> n;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getMBitsAtN(Byte input, size_t m, size_t n)
|
||||
unsigned char Bits::getMBitsAtN(Byte input, size_t m, size_t n)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
|
@ -94,12 +93,12 @@ unsigned char ByteUtils::getMBitsAtN(Byte input, size_t m, size_t n)
|
|||
}
|
||||
}
|
||||
|
||||
bool ByteUtils::getBitN(DWord input, size_t n)
|
||||
bool Bits::getBitN(DWord input, size_t n)
|
||||
{
|
||||
return input & (1 << n);
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getFromString(const String& string)
|
||||
unsigned char Bits::getFromString(const String& string)
|
||||
{
|
||||
unsigned char ret{0};
|
||||
|
||||
|
@ -118,7 +117,7 @@ unsigned char ByteUtils::getFromString(const String& string)
|
|||
return ret;
|
||||
}
|
||||
|
||||
String ByteUtils::toString(DWord input, size_t length)
|
||||
String Bits::toString(DWord input, size_t length)
|
||||
{
|
||||
String ret;
|
||||
if (length > 8)
|
||||
|
@ -144,7 +143,7 @@ String ByteUtils::toString(DWord input, size_t length)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void ByteUtils::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize)
|
||||
void Bits::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t targetSize)
|
||||
{
|
||||
for(unsigned idx=0; idx<targetSize; idx++)
|
||||
{
|
||||
|
@ -159,22 +158,22 @@ void ByteUtils::ReverseBuffer(Byte* buffer, char* reverse, size_t size, size_t t
|
|||
}
|
||||
}
|
||||
|
||||
Word ByteUtils::ToWord(Byte* buffer, bool reverse)
|
||||
Word Bits::ToWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<Word>(buffer, reverse);
|
||||
}
|
||||
|
||||
DWord ByteUtils::ToDWord(Byte* buffer, bool reverse)
|
||||
DWord Bits::ToDWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<DWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
QWord ByteUtils::ToQWord(Byte* buffer, bool reverse)
|
||||
QWord Bits::ToQWord(Byte* buffer, bool reverse)
|
||||
{
|
||||
return ToType<QWord>(buffer, reverse);
|
||||
}
|
||||
|
||||
bool ByteUtils::Compare(Byte* buffer, const char* tag, size_t size)
|
||||
bool Bits::Compare(Byte* buffer, const char* tag, size_t size)
|
||||
{
|
||||
for(unsigned idx=0; idx<size; idx++)
|
||||
{
|
||||
|
@ -186,12 +185,24 @@ bool ByteUtils::Compare(Byte* buffer, const char* tag, size_t size)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareDWords(Byte* buffer, const char* tag)
|
||||
bool Bits::CompareDWords(Byte* buffer, DWord target)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(DWord));
|
||||
for(size_t idx=0; idx<4;idx++)
|
||||
{
|
||||
if (buffer[idx] != getByteN(target, idx))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ByteUtils::CompareWords(Byte* buffer, const char* tag)
|
||||
bool Bits::CompareWords(Byte* buffer, Word target)
|
||||
{
|
||||
return Compare(buffer, tag, sizeof(Word));
|
||||
bool first_byte_matches = (buffer[0] == GetWordFirstBit(target));
|
||||
if (!first_byte_matches)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return buffer[1] == GetWordLastByte(target);
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
#include "ByteTypes.h"
|
||||
#include "String.h"
|
||||
|
||||
class ByteUtils
|
||||
class Bits
|
||||
{
|
||||
public:
|
||||
static bool MostSignificantBitIsOne(Byte c);
|
||||
|
@ -57,9 +57,9 @@ public:
|
|||
|
||||
static bool Compare(Byte* buffer, const char* tag, size_t size);
|
||||
|
||||
static bool CompareDWords(Byte* buffer, const char* tag);
|
||||
static bool CompareDWords(Byte* buffer, DWord target);
|
||||
|
||||
static bool CompareWords(Byte* buffer, const char* tag);
|
||||
static bool CompareWords(Byte* buffer, Word target);
|
||||
|
||||
static const int BYTE_FIRST_BIT = 0x40; // 1000 0000
|
||||
static const Word WORD_FIRST_BIT = static_cast<Word>(0x8000); // 1000 0000 - 0000 0000
|
|
@ -1,35 +0,0 @@
|
|||
#include "CharUtils.h"
|
||||
|
||||
bool CharUtils::is_alpha_upper(char c)
|
||||
{
|
||||
const auto unsigned_c = static_cast<unsigned char>(c);
|
||||
return unsigned_c >= 65 && unsigned_c <= 90;
|
||||
}
|
||||
|
||||
bool CharUtils::is_alpha_lower(char c)
|
||||
{
|
||||
const auto unsigned_c = static_cast<unsigned char>(c);
|
||||
return unsigned_c >= 97 && unsigned_c <= 122;
|
||||
}
|
||||
|
||||
bool CharUtils::is_alpha(char c)
|
||||
{
|
||||
return is_alpha_upper(c) || is_alpha_lower(c);
|
||||
}
|
||||
|
||||
bool CharUtils::is_alnum(char c)
|
||||
{
|
||||
return is_alpha(c) || is_digit(c);
|
||||
}
|
||||
|
||||
bool CharUtils::is_digit(char c)
|
||||
{
|
||||
const auto unsigned_c = static_cast<unsigned char>(c);
|
||||
return unsigned_c >= 48 && unsigned_c <= 57;
|
||||
}
|
||||
|
||||
bool CharUtils::is_space(char c)
|
||||
{
|
||||
return c == ' ' || c == '\f' || c == '\n'
|
||||
|| c == '\r' || c == '\t' || c == '\v';
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class CharUtils
|
||||
{
|
||||
public:
|
||||
static bool is_alpha_upper(char c);
|
||||
|
||||
static bool is_alpha_lower(char c);
|
||||
|
||||
static bool is_alpha(char c);
|
||||
|
||||
static bool is_alnum(char c);
|
||||
|
||||
static bool is_digit(char c);
|
||||
|
||||
static bool is_space(char c);
|
||||
};
|
|
@ -1,60 +1,15 @@
|
|||
#include "StringUtils.h"
|
||||
|
||||
#include "Char.h"
|
||||
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
bool StringUtils::isAlphaNumeric(char c)
|
||||
{
|
||||
return std::isalnum(c);
|
||||
}
|
||||
|
||||
bool StringUtils::isSpace(char c)
|
||||
{
|
||||
return std::isspace(c);
|
||||
}
|
||||
|
||||
bool StringUtils::isAlphabetical(char c)
|
||||
{
|
||||
return std::isalpha(c);
|
||||
}
|
||||
|
||||
Vector<unsigned char> StringUtils::toBytes(const String& input)
|
||||
{
|
||||
return {input.begin(), input.end()};
|
||||
}
|
||||
|
||||
String StringUtils::toString(const Vector<unsigned char>& bytes)
|
||||
{
|
||||
return {bytes.begin(), bytes.end()};
|
||||
}
|
||||
|
||||
Vector<String> StringUtils::toLines(const String& input)
|
||||
{
|
||||
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 String& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::all_of(input.cbegin(), input.cend(), [](char c){ return std::isspace(c); });
|
||||
}
|
||||
}
|
||||
|
||||
size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
||||
{
|
||||
/*
|
||||
auto found_id = input.find(c);
|
||||
if(found_id == String::npos)
|
||||
{
|
||||
|
@ -76,10 +31,13 @@ size_t StringUtils::countFirstConsecutiveHits(const String& input, char c)
|
|||
}
|
||||
return count;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
String StringUtils::stripSurroundingWhitepsace(const String& input)
|
||||
{
|
||||
/*
|
||||
if (input.empty())
|
||||
{
|
||||
return {};
|
||||
|
@ -110,54 +68,24 @@ String StringUtils::stripSurroundingWhitepsace(const String& input)
|
|||
}
|
||||
}
|
||||
return input.substr(first_nonspace, last_nonspace-first_nonspace + 1);
|
||||
}
|
||||
|
||||
Vector<String> StringUtils::split(const String& input)
|
||||
{
|
||||
Vector<String> substrings;
|
||||
String working_string;
|
||||
std::locale loc;
|
||||
bool last_was_nonspace{ false };
|
||||
for (auto c : input)
|
||||
{
|
||||
if (std::isspace(c, loc))
|
||||
{
|
||||
if (last_was_nonspace)
|
||||
{
|
||||
substrings.push_back(working_string);
|
||||
working_string = "";
|
||||
last_was_nonspace = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last_was_nonspace = true;
|
||||
working_string += c;
|
||||
}
|
||||
}
|
||||
if (!working_string.empty())
|
||||
{
|
||||
substrings.push_back(working_string);
|
||||
}
|
||||
return substrings;
|
||||
}
|
||||
|
||||
String StringUtils::toLower(const String& s)
|
||||
{
|
||||
String ret;
|
||||
std::transform(s.begin(), s.end(), ret.begin(), [](unsigned char c){ return std::tolower(c); });
|
||||
return ret;
|
||||
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
String StringUtils::toPaddedString(unsigned numBytes, unsigned entry)
|
||||
{
|
||||
/*
|
||||
Stringstream sstr;
|
||||
sstr << std::setfill('0') << std::setw(numBytes) << entry;
|
||||
return sstr.str();
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
String StringUtils::stripQuotes(const String& input)
|
||||
{
|
||||
/*
|
||||
if (input.size() < 3)
|
||||
{
|
||||
return input;
|
||||
|
@ -173,10 +101,13 @@ String StringUtils::stripQuotes(const String& input)
|
|||
end_index = end_index - 1;
|
||||
}
|
||||
return input.substr(start_index, end_index - start_index + 1);
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
String StringUtils::removeUpTo(const String& input, const String& prefix)
|
||||
{
|
||||
/*
|
||||
size_t found = input.find(prefix);
|
||||
if (found != String::npos)
|
||||
{
|
||||
|
@ -186,10 +117,13 @@ String StringUtils::removeUpTo(const String& input, const String& prefix)
|
|||
{
|
||||
return input;
|
||||
}
|
||||
*/
|
||||
return {};
|
||||
}
|
||||
|
||||
bool StringUtils::startsWith(const String& input, const String& prefix, bool ignoreWhitespace)
|
||||
{
|
||||
/*
|
||||
if(ignoreWhitespace)
|
||||
{
|
||||
const auto loc = input.find(prefix);
|
||||
|
@ -206,4 +140,6 @@ bool StringUtils::startsWith(const String& input, const String& prefix, bool ign
|
|||
{
|
||||
return input.find(prefix) == 0;
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8,43 +8,15 @@
|
|||
class StringUtils
|
||||
{
|
||||
public:
|
||||
static constexpr char LEFT_BRACKET = '<';
|
||||
static constexpr char RIGHT_BRACKET = '>';
|
||||
static constexpr char FORWARD_SLASH = '/';
|
||||
static constexpr char BACK_SLASH = '\\';
|
||||
static constexpr char QUESTION_MARK = '?';
|
||||
static constexpr char EQUALS = '=';
|
||||
static constexpr char DOUBLE_QUOTE = '"';
|
||||
static constexpr char SINGLE_QUOTE = '\'';
|
||||
static constexpr char COLON = ':';
|
||||
|
||||
static size_t countFirstConsecutiveHits(const String& input, char c);
|
||||
|
||||
static bool isAlphaNumeric(char c);
|
||||
|
||||
static bool isAlphabetical(char c);
|
||||
|
||||
static bool isSpace(char c);
|
||||
|
||||
static bool isWhitespaceOnly(const String& input);
|
||||
|
||||
static String removeUpTo(const String& input, const String& prefix);
|
||||
|
||||
static Vector<String> split(const String& input);
|
||||
|
||||
static bool startsWith(const String& input, const String& prefix, bool ignoreWhitespace = false);
|
||||
|
||||
static String stripSurroundingWhitepsace(const String& input);
|
||||
|
||||
static String stripQuotes(const String& input);
|
||||
|
||||
static Vector<unsigned char> toBytes(const String& input);
|
||||
|
||||
static String toLower(const String& s);
|
||||
|
||||
static Vector<String> toLines(const String& input);
|
||||
|
||||
static String toPaddedString(unsigned numBytes, unsigned entry);
|
||||
|
||||
static String toString(const Vector<unsigned char>& bytes);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "UnicodeUtils.h"
|
||||
#include "Unicode.h"
|
||||
|
||||
#include "Win32BaseIncludes.h"
|
||||
|
||||
|
@ -45,7 +45,7 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const String& input)
|
|||
}
|
||||
*/
|
||||
|
||||
Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
||||
Vector<uint32_t> Unicode::utf8ToUtf32(const String& input)
|
||||
{
|
||||
//const auto utf_16 = utf8ToUtf16WString(input);
|
||||
|
||||
|
@ -77,22 +77,22 @@ Vector<uint32_t> UnicodeUtils::utf8ToUtf32(const String& input)
|
|||
return output;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isSurrogate(wchar_t c)
|
||||
bool Unicode::isSurrogate(wchar_t c)
|
||||
{
|
||||
return (c - 0xd800u) < 2048u;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isHighSurrogate(wchar_t c)
|
||||
bool Unicode::isHighSurrogate(wchar_t c)
|
||||
{
|
||||
return (c & 0xfffffc00) == 0xd800;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isLowSurrogate(wchar_t c)
|
||||
bool Unicode::isLowSurrogate(wchar_t c)
|
||||
{
|
||||
return (c & 0xfffffc00) == 0xdc00;
|
||||
}
|
||||
|
||||
uint32_t UnicodeUtils::surrogateToUtf32(wchar_t high, wchar_t low)
|
||||
uint32_t Unicode::surrogateToUtf32(wchar_t high, wchar_t low)
|
||||
{
|
||||
return (high << 10) + low - 0x35fdc00;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
#include "Vector.h"
|
||||
#include <cstdint>
|
||||
|
||||
class UnicodeUtils
|
||||
class Unicode
|
||||
{
|
||||
public:
|
||||
//static String utf16ToUtf8String(const std::wstring& input);
|
Loading…
Add table
Add a link
Reference in a new issue