Initial test bootstrap.

This commit is contained in:
jmsgrogan 2023-12-18 10:16:31 +00:00
parent 6c618749f1
commit 4b308f6c32
94 changed files with 2543 additions and 681 deletions

View file

@ -1,44 +1,40 @@
#pragma once
#include "ByteTypes.h"
#include "String.h"
#include <cstring>
#include <stdint.h>
#include <string>
class ByteUtils
{
public:
using Word = int16_t;
using DWord = int32_t;
using QWord = int64_t;
static bool MostSignificantBitIsOne(char c);
static bool MostSignificantBitIsOne(Byte c);
static Word GetWordFirstBit(const Word word);
static Word GetWordLastByte(const Word word);
static unsigned char getByteN(uint32_t input, unsigned n);
static Byte getByteN(DWord input, std::size_t n);
static unsigned char getHigherNBits(unsigned char input, unsigned num);
static Byte getHigherNBits(Byte input, std::size_t num);
static unsigned char getLowerNBits(uint32_t input, unsigned num);
static Byte getLowerNBits(DWord input, std::size_t num);
static unsigned char getTwoBitsAtN(unsigned char input, unsigned n);
static Byte getTwoBitsAtN(Byte input, std::size_t n);
static unsigned char getMBitsAtN(unsigned char input, unsigned m, unsigned n);
static Byte getMBitsAtN(Byte input, std::size_t m, std::size_t n);
static bool getBitN(uint32_t input, unsigned n);
static bool getBitN(DWord input, std::size_t n);
static unsigned char getFromString(const std::string& string);
static Byte getFromString(const String& string);
static std::string toString(uint32_t input, unsigned length = 8);
static String toString(DWord input, std::size_t length = 8);
static uint32_t mirror(uint32_t input, unsigned length=0);
static DWord mirror(DWord input, std::size_t length=0);
static void ReverseBuffer(char* buffer, char* reverse, unsigned size, unsigned targetSize);
static void ReverseBuffer(Byte* buffer, Byte* reverse, std::size_t size, std::size_t targetSize);
template<typename T>
static T ToType(char* buffer, bool reverse = true)
static T ToType(Byte* buffer, bool reverse = true)
{
T result {0};
if(reverse)
@ -54,17 +50,17 @@ public:
return result;
}
static Word ToWord(char* buffer, bool reverse = true);
static Word ToWord(Byte* buffer, bool reverse = true);
static DWord ToDWord(char* buffer, bool reverse = true);
static DWord ToDWord(Byte* buffer, bool reverse = true);
static QWord ToQWord(char* buffer, bool reverse = true);
static QWord ToQWord(Byte* buffer, bool reverse = true);
static bool Compare(char* buffer, const char* tag, unsigned size);
static bool Compare(Byte* buffer, const char* tag, std::size_t size);
static bool CompareDWords(char* buffer, const char* tag);
static bool CompareDWords(Byte* buffer, const char* tag);
static bool CompareWords(char* buffer, const char* tag);
static bool CompareWords(Byte* buffer, const char* tag);
static const int BYTE_FIRST_BIT = 0x40; // 1000 0000
static const Word WORD_FIRST_BIT = static_cast<Word>(0x8000); // 1000 0000 - 0000 0000

View file

@ -0,0 +1,35 @@
#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';
}

View file

@ -0,0 +1,17 @@
#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);
};

View file

@ -1,5 +1,7 @@
#pragma once
#include "ByteTypes.h"
#include <string>
#include <vector>