- Switched from Allman (BSD) to 1TBS (K&R)

Namespaces, Types, and Requires/Concepts still use Allman
This commit is contained in:
2025-07-08 12:07:44 -04:00
parent 2573de0904
commit 649e39c70e
32 changed files with 419048 additions and 877 deletions

View File

@@ -51,8 +51,8 @@ public:
///
/// \brief Default Constructor, initializes empty string
constexpr _string()
: _str()
{ }
: _str() {
}
///
/// \brief Sized Constructor, initializes a null-terminated string of size `n` with null characters
@@ -60,8 +60,8 @@ public:
///
/// \details adds additional character for null termination.
constexpr _string(size_t n)
: _string('\0', n)
{ }
: _string('\0', n) {
}
///
/// \brief Sized Constructor, initializes a null-terminated string of size `n` filled with the character `c`
@@ -70,8 +70,9 @@ public:
///
/// \details adds additional character for null termination.
constexpr _string(char c, size_t n)
: _str(n + 1)
{ fennec::memset(_str, c, n); _str[n] = '\0'; }
: _str(n + 1) {
fennec::memset(_str, c, n); _str[n] = '\0';
}
///
/// \brief Buffer Copy Constructor
@@ -81,19 +82,19 @@ public:
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
/// This constructor makes the assumption that `len` is the intended number of characters.
constexpr _string(const cstring& str)
: _str(str, str.size() + 1)
{ _str[str.size()] = '\0'; }
: _str(str, str.size() + 1) {
_str[str.size()] = '\0';
}
///
/// \brief String Copy Constructor
/// \param str the string to copy
constexpr _string(const string& str)
: _string(str, str.size() - 1)
{ }
: _string(str, str.size() - 1) {
}
constexpr _string(_string&& str) noexcept
: _str(fennec::move(str._str))
{ }
: _str(fennec::move(str._str)) { }
///
/// \brief String Destructor, cleans up the underlying allocation
@@ -103,7 +104,9 @@ public:
///
/// \returns The size of the string excluding null terminator
constexpr size_t size() const { return _str.capacity() - 1; }
constexpr size_t size() const {
return _str.capacity() - 1;
}
// Access ==============================================================================================================
@@ -129,34 +132,38 @@ public:
///
/// \brief Dereference Operator
/// \returns A const qualified pointer to the underlying allocation
constexpr const char* operator*() const { return _str; }
constexpr const char* operator*() const {
return _str;
}
///
/// \brief Implicit Dereference Cast
constexpr operator const char*() const { return _str; }
constexpr operator const char*() const {
return _str; }
// Examination =========================================================================================================
///
/// \returns The length of the string to the first null-terminator
constexpr size_t length() const
{ return find('\0'); }
constexpr size_t length() const {
return find('\0');
}
///
/// \brief String Comparison
/// \param ostr the string to compare against
/// \returns Zero if both strings are equal, otherwise a negative value if lhs appears before rhs according to the
/// current locale, otherwise a positive value.
constexpr int compare(const string& ostr) const
{ return ::strcoll(_str, ostr); }
constexpr int compare(const string& ostr) const {
return ::strcoll(_str, ostr);
}
///
/// \brief Finds the index of the first occurrence of `x` in the string
/// \param x the character to find
/// \returns The index of `x` if it occurs in the string, otherwise returns `size()`
constexpr size_t find(char x) const
{
constexpr size_t find(char x) const {
const char* loc = ::strchr(_str, x);
return loc ? loc - _str : size();
}
@@ -165,8 +172,7 @@ public:
/// \brief Finds the index of the first occurrence of `str` in the string.
/// \param str the string to find
/// \returns The index of `str` if it occurs in the string, otherwise returns `size()`
constexpr size_t find(const string& str) const
{
constexpr size_t find(const string& str) const {
const char* loc = ::strstr(_str, str);
return loc ? loc - _str : size();
}
@@ -175,8 +181,7 @@ public:
/// \brief Finds the index of the first occurrence of `str` in the string.
/// \param str the string to find
/// \returns The index of `str` if it occurs in the string, otherwise returns `size()`
constexpr size_t find(const cstring& str) const
{
constexpr size_t find(const cstring& str) const {
const char* loc = ::strstr(_str, str);
return loc ? loc - _str : size();
}
@@ -186,8 +191,7 @@ public:
/// \param c the string to find
/// \param i the index to start at
/// \returns The index of `c` if it occurs in the string, otherwise returns `size()`
constexpr size_t rfind(char c, size_t i = 0) const
{
constexpr size_t rfind(char c, size_t i = size()) const {
if (size() == 0) return size();
i = min(i, size() - 1); // clamp i to bounds
do {
@@ -201,8 +205,7 @@ public:
/// \param str the string to find
/// \param i the index to start at
/// \returns The index of `str` if it occurs in the string, otherwise returns `size()`
constexpr size_t rfind(const cstring& str, size_t i = 0) const
{
constexpr size_t rfind(const cstring& str, size_t i = size()) const {
const char first = str[0];
i = min(i, size() - str.size());
do {
@@ -217,8 +220,7 @@ public:
/// \param str the string to find
/// \param i the index to start at
/// \returns The index of `str` if it occurs in the string, otherwise returns `size()`
constexpr size_t rfind(const string& str, size_t i = 0) const
{
constexpr size_t rfind(const string& str, size_t i = size()) const {
const char first = str[0];
i = min(i, size() - str.size());
do {
@@ -233,8 +235,7 @@ public:
///
/// \brief Resize the string, filling additional bytes with `'\0'`
/// \param n the new size of the string
constexpr void resize(size_t n)
{
constexpr void resize(size_t n) {
size_t i = size();
_str.reallocate(n + 1);
if (n > i) fennec::memset(*_str + i, '\0', n - i);
@@ -244,8 +245,7 @@ public:
/// \brief Copy Assignment Operator
/// \param str the string to copy
/// \returns a reference to `this`
constexpr string& operator=(const string& str)
{
constexpr string& operator=(const string& str) {
if (str.size() > size()) string::resize(str.size());
fennec::memcpy(_str, str, str.size());
_str[str.size()] = '\0';
@@ -256,8 +256,7 @@ public:
/// \brief Move Assignment Operator
/// \param str the string to move
/// \returns a reference to `this`
constexpr string& operator=(string&& str) noexcept
{
constexpr string& operator=(string&& str) noexcept {
_str = fennec::move(str._str);
return *this;
}
@@ -267,8 +266,7 @@ public:
/// \param i the start index
/// \param n the number of characters
/// \return
constexpr string substring(size_t i, size_t n = size())
{
constexpr string substring(size_t i, size_t n = size()) const {
assert(i < size(), "Array Out of Bounds");
n = min(n, size() - i);
return string(&_str[i], n);
@@ -278,50 +276,44 @@ public:
/// \brief Returns a string with `c` appended to it
/// \param c
/// \returns
constexpr string operator+(char c)
{
constexpr string operator+(char c) const {
// Copy contents with one additional byte.
string res(_str, _str.size());
res[size()] = c; // Set the last character to c
return res;
}
constexpr string operator+(const string& str)
{
constexpr string operator+(const cstring& str) const {
string res(size() + str.size()); // Make a new string with the size of this + str
fennec::memcpy(res, _str, size()); // Copy the contents of this
fennec::memcpy(&res[size()], str, str.size()); // Append the contents of str
return res;
}
constexpr string operator+(const cstring& str)
{
constexpr string operator+(const string& str) const {
string res(size() + str.size()); // Make a new string with the size of this + str
fennec::memcpy(res, _str, size()); // Copy the contents of this
fennec::memcpy(&res[size()], str, str.size()); // Append the contents of str
return res;
}
constexpr string& operator+=(char c)
{
constexpr string& operator+=(char c) {
size_t x = size();
resize(x + 1);
_str[x] = c;
return *this;
}
constexpr string& operator+=(const string& str)
{
constexpr string& operator+=(const cstring& str) {
size_t x = size();
string::resize(x + str.size());
resize(x + str.size());
fennec::memcpy(&_str[x], str, str.size());
return *this;
}
constexpr string& operator+=(const cstring& str)
{
constexpr string& operator+=(const string& str) {
size_t x = size();
resize(x + str.size());
string::resize(x + str.size());
fennec::memcpy(&_str[x], str, str.size());
return *this;
}