[ox/std] Cleanup
This commit is contained in:
parent
0a0a6e306d
commit
7163947efd
75
deps/ox/src/ox/std/istring.hpp
vendored
75
deps/ox/src/ox/std/istring.hpp
vendored
@ -10,17 +10,17 @@
|
|||||||
|
|
||||||
#include "ignore.hpp"
|
#include "ignore.hpp"
|
||||||
#include "memops.hpp"
|
#include "memops.hpp"
|
||||||
|
#include "ox/std/error.hpp"
|
||||||
#include "stringview.hpp"
|
#include "stringview.hpp"
|
||||||
#include "strops.hpp"
|
|
||||||
#include "typetraits.hpp"
|
#include "typetraits.hpp"
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
// Inline String
|
// Inline String
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
class IString {
|
class IString {
|
||||||
private:
|
private:
|
||||||
char m_buff[buffLen + 1];
|
char m_buff[StrCap + 1];
|
||||||
size_t m_size{};
|
size_t m_size{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -87,6 +87,8 @@ class IString {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr std::size_t bytes() const noexcept;
|
constexpr std::size_t bytes() const noexcept;
|
||||||
|
|
||||||
|
constexpr ox::Error resize(size_t sz) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the capacity of bytes for this string.
|
* Returns the capacity of bytes for this string.
|
||||||
*/
|
*/
|
||||||
@ -192,38 +194,38 @@ constexpr IString<size> IString<size>::operator+(Integer_c auto i) const noexcep
|
|||||||
return this->operator+(str);
|
return this->operator+(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr bool IString<buffLen>::operator==(const char *other) const noexcept {
|
constexpr bool IString<StrCap>::operator==(const char *other) const noexcept {
|
||||||
return ox::StringView(*this) == other;
|
return ox::StringView(*this) == other;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr bool IString<buffLen>::operator==(const OxString_c auto &other) const noexcept {
|
constexpr bool IString<StrCap>::operator==(const OxString_c auto &other) const noexcept {
|
||||||
return ox::StringView(*this) == ox::StringView(other);
|
return ox::StringView(*this) == ox::StringView(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr bool IString<buffLen>::operator!=(const char *other) const noexcept {
|
constexpr bool IString<StrCap>::operator!=(const char *other) const noexcept {
|
||||||
return !operator==(other);
|
return !operator==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr bool IString<buffLen>::operator!=(const OxString_c auto &other) noexcept {
|
constexpr bool IString<StrCap>::operator!=(const OxString_c auto &other) noexcept {
|
||||||
return !operator==(other);
|
return !operator==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr char IString<buffLen>::operator[](std::size_t i) const noexcept {
|
constexpr char IString<StrCap>::operator[](std::size_t i) const noexcept {
|
||||||
return m_buff[i];
|
return m_buff[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr char &IString<buffLen>::operator[](std::size_t i) noexcept {
|
constexpr char &IString<StrCap>::operator[](std::size_t i) noexcept {
|
||||||
return m_buff[i];
|
return m_buff[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr Error IString<buffLen>::append(const char *str, std::size_t strLen) noexcept {
|
constexpr Error IString<StrCap>::append(const char *str, std::size_t strLen) noexcept {
|
||||||
Error err;
|
Error err;
|
||||||
auto currentLen = len();
|
auto currentLen = len();
|
||||||
if (cap() < currentLen + strLen + 1) {
|
if (cap() < currentLen + strLen + 1) {
|
||||||
@ -236,26 +238,26 @@ constexpr Error IString<buffLen>::append(const char *str, std::size_t strLen) no
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr const char *IString<buffLen>::data() const noexcept {
|
constexpr const char *IString<StrCap>::data() const noexcept {
|
||||||
return static_cast<const char*>(m_buff);
|
return static_cast<const char*>(m_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr char *IString<buffLen>::data() noexcept {
|
constexpr char *IString<StrCap>::data() noexcept {
|
||||||
return static_cast<char*>(m_buff);
|
return static_cast<char*>(m_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr const char *IString<buffLen>::c_str() const noexcept {
|
constexpr const char *IString<StrCap>::c_str() const noexcept {
|
||||||
return static_cast<const char*>(m_buff);
|
return static_cast<const char*>(m_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr std::size_t IString<buffLen>::len() const noexcept {
|
constexpr std::size_t IString<StrCap>::len() const noexcept {
|
||||||
std::size_t length = 0;
|
std::size_t length = 0;
|
||||||
for (std::size_t i = 0; i < buffLen; i++) {
|
for (std::size_t i = 0; i < StrCap; i++) {
|
||||||
uint8_t b = static_cast<uint8_t>(m_buff[i]);
|
uint8_t b = static_cast<uint8_t>(m_buff[i]);
|
||||||
if (b) {
|
if (b) {
|
||||||
const auto asciiChar = (b & 128) == 0;
|
const auto asciiChar = (b & 128) == 0;
|
||||||
@ -270,16 +272,25 @@ constexpr std::size_t IString<buffLen>::len() const noexcept {
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr std::size_t IString<buffLen>::bytes() const noexcept {
|
constexpr std::size_t IString<StrCap>::bytes() const noexcept {
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
for (i = 0; i < buffLen && m_buff[i]; i++);
|
for (i = 0; i < StrCap && m_buff[i]; i++);
|
||||||
return i + 1; // add one for null terminator
|
return i + 1; // add one for null terminator
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
template<std::size_t StrCap>
|
||||||
constexpr std::size_t IString<buffLen>::cap() const noexcept {
|
constexpr ox::Error IString<StrCap>::resize(size_t sz) noexcept {
|
||||||
return buffLen;
|
if (sz > StrCap) {
|
||||||
|
return OxError(1, "Trying to extend IString beyond its cap");
|
||||||
|
}
|
||||||
|
m_size = sz;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t StrCap>
|
||||||
|
constexpr std::size_t IString<StrCap>::cap() const noexcept {
|
||||||
|
return StrCap;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t sz>
|
template<size_t sz>
|
||||||
|
5
deps/ox/src/ox/std/uuid.hpp
vendored
5
deps/ox/src/ox/std/uuid.hpp
vendored
@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "array.hpp"
|
|
||||||
#include "istring.hpp"
|
#include "istring.hpp"
|
||||||
#include "buffer.hpp"
|
#include "buffer.hpp"
|
||||||
#include "random.hpp"
|
#include "random.hpp"
|
||||||
#include "ranges.hpp"
|
#include "ranges.hpp"
|
||||||
#include "stringview.hpp"
|
#include "stringview.hpp"
|
||||||
|
#include "strops.hpp"
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
@ -80,7 +80,8 @@ constexpr ox::IString<2> toHex(uint8_t v) noexcept {
|
|||||||
'e',
|
'e',
|
||||||
'f',
|
'f',
|
||||||
};
|
};
|
||||||
ox::Array<char, 3> out;
|
ox::IString<2> out;
|
||||||
|
std::ignore = out.resize(2);
|
||||||
out[0] = valMap[static_cast<unsigned>((v & 0xf0) / 16)];
|
out[0] = valMap[static_cast<unsigned>((v & 0xf0) / 16)];
|
||||||
out[1] = valMap[static_cast<unsigned>(v & 0x0f)];
|
out[1] = valMap[static_cast<unsigned>(v & 0x0f)];
|
||||||
out[2] = 0;
|
out[2] = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user