some changes

This commit is contained in:
2026-07-29 10:22:20 -06:00
parent 8f208f436c
commit a23f9f7855
12 changed files with 117 additions and 240 deletions
-104
View File
@@ -1,104 +0,0 @@
#pragma once
#include <ckitty/memory/primitives.hpp>
#include <string>
#include <algorithm>
#include <cctype>
#include <locale>
namespace ckitty {
namespace strings {
// trim spaces
inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
[](unsigned char ch) {
return !std::isspace(ch);
}));
}
inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(),
[](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
}
inline void trim(std::string& str) {
ltrim(str);
rtrim(str);
}
inline std::string trimc(const std::string& str) {
std::string copy = str;
trim(copy);
return copy;
}
inline std::string ltrimc(const std::string& str) {
std::string copy = str;
ltrim(copy);
return copy;
}
inline std::string rtrimc(const std::string& str) {
std::string copy = str;
rtrim(copy);
return copy;
}
/**
* Returns a displayable representation of the character.
*/
inline std::string display(char c) {
if(std::isprint(c)) return std::string(1, c);
char chars[] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'
};
std::string str = "0x00";
str[2] = chars[ (c >> 4) & 0xF ];
str[3] = chars[ c & 0xF ];
return str;
}
inline int hexChar(char c) {
if('0' <= c && c <= '9') return c - '0';
if('a' <= c && c <= 'f') return c - 'a' + 10;
if('A' <= c && c <= 'F') return c - 'A' + 10;
return -1;
}
// ascii upper & lower
inline void upper(std::string& str) {
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
}
inline void lower(std::string& str) {
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
}
inline std::string copy_upper(const std::string& str) {
std::string copy = str;
upper(copy);
return copy;
}
inline std::string copy_lower(const std::string& str) {
std::string copy = str;
lower(copy);
return copy;
}
// ...
}
}
-86
View File
@@ -1,86 +0,0 @@
#pragma once
#include <ckitty/memory/array.hpp>
#include <ckitty/system/strings.hpp>
/*
* NOTICE: This is the standalone unicode library for ckittylib.
* If using ICU, use the /unicode folder's headers.
*/
namespace ckitty {
namespace unicode {
using sequences = std::string;
using string = std::u32string;
/**
* Returns the amount of bytes needed to
* represent an UTF-8 character given
* the first byte of the sequence.
*
* Returns 0 for invalid sequences.
*/
inline u32 sequenceLength(const u8 head) {
return (head - 160 >> 20 - head / 16) + 2;
}
/**
* Encodes a UTF-32 character into a UTF-8 sequence.
*/
inline sequences encodeChar(const u32 cha) {}
/**
* Decodes a UTF-8 sequence (the first one) into a UTF-32 character.
* Invalid sequences return 0 and raise a flag.
*/
inline u32 decodeChar(const sequences& cha, bool* error = nullptr) {}
inline sequences encodeChar(const u32 cha) {}
struct decode_result {
// Was the result valid?
bool valid = false;
// First character error.
u64 errCharIndex = 0;
// Byte index of character.
u64 errByteIndex = 0;
// UTF32 result
string output;
};
/**
* Decodes all UTF-8 sequences into 32 bit chars.
* Invalid ones are read as one byte.
*/
inline decode_result decodeUTF8(const sequences& str) {
decode_result r;
return r;
}
/**
* Encodes UTF32 into UTF-8 byte sequences.
*/
inline sequences encodeUTF8(const string& str) {}
struct validate_result {
// Was the result valid?
bool valid = false;
// First character error.
u64 errCharIndex = 0;
// Byte index of character.
u64 errByteIndex = 0;
};
/**
* Validates that a std::string is made out of valid UTF8 sequences.
*/
inline validate_result validateUTF8(const sequences& str) {
validate_result r;
return r;
}
}
}