7#include "libxr_def.hpp"
19template <
unsigned int MaxLength>
73 ASSERT(i < MaxLength);
86 ASSERT(i < MaxLength);
108 auto len = strnlen(this->
Raw(), MaxLength);
109 size_t copy_len =
LibXR::min(MaxLength - len, std::strlen(str));
122 int Find(
const char *str)
const
128 const char *result = std::strstr(this->
Raw(), str);
129 return result ?
static_cast<int>(result - this->
Raw()) : -1;
140 template <
unsigned int NextStrLength>
143 return strncmp(this->
Raw(), other.
Raw(), MaxLength) == 0;
154 template <
unsigned int NextStrLength>
157 return strncmp(this->
Raw(), other.
Raw(), MaxLength) != 0;
168 template <
unsigned int NextStrLength>
171 return strncmp(this->
Raw(), other.
Raw(), MaxLength) < 0;
182 template <
unsigned int NextStrLength>
185 return strncmp(this->
Raw(), other.
Raw(), MaxLength) > 0;
196 template <
unsigned int NextStrLength>
199 return strncmp(this->
Raw(), other.
Raw(), MaxLength) <= 0;
210 template <
unsigned int NextStrLength>
213 return strncmp(this->
Raw(), other.
Raw(), MaxLength) >= 0;
222 size_t Length()
const {
return strnlen(this->
Raw(), MaxLength); }
239 template <
unsigned int SubStrLength>
242 ASSERT(pos < MaxLength);
A fixed-length string class with safe operations.
int Find(const char *str) const
Finds the first occurrence of a substring.
bool operator==(const String< NextStrLength > &other) const
Compares two strings for equality.
bool operator!=(const String< NextStrLength > &other) const
Compares two strings for inequality.
String(const char *str)
Constructs a String from a C-style string.
String< SubStrLength > Substr(size_t pos) const
Extracts a substring starting at a given position.
bool operator>(const String< NextStrLength > &other) const
Greater than comparison between two strings.
String(const char *str, size_t len)
Constructs a String from a C-style string with a given length.
char operator[](unsigned int i)
Accesses a character at a given index.
char operator[](unsigned int i) const
Accesses a character at a given index (const version).
std::array< char, MaxLength+1 > raw_string_
bool operator<(const String< NextStrLength > &other) const
Less than comparison between two strings.
bool operator>=(const String< NextStrLength > &other) const
Greater than or equal comparison.
bool operator<=(const String< NextStrLength > &other) const
Less than or equal comparison.
size_t Length() const
Gets the length of the string.
String & operator+=(const char *str)
Appends a C-style string to the current string.
void Clear()
Clears the string, making it empty.
const char * operator+(unsigned int i)
Returns a pointer to a substring starting from index i.
String()
Default constructor, initializes an empty string.
const char * Raw() const
Gets the raw C-style string.
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值