19#ifndef FENNEC_STRING_wcstring_H
20#define FENNEC_STRING_wcstring_H
22#include <fennec/string/detail/_ctype.h>
23#include <fennec/memory/detail/_string.h>
62 static constexpr size_t npos = -1;
63 using char_t = wchar_t;
70 : _str(nullptr), _size(0), _const(true) {
76 : _str(nullptr), _size(0), _const(true) {
87 assert(_str[n - 1] ==
'\0',
"Invalid NTBS.");
99 assert(_str[n - 1] ==
'\0',
"Invalid NTBS.");
110 assert(_cstr[n - 1] ==
'\0',
"Invalid NTBS.");
122 assert(_cstr[n - 1] ==
'\0',
"Invalid NTBS.");
131 , _const(str._const) {
142 _str =
nullptr, _size = 0, _const =
true;
148 constexpr wcstring& operator=(
wchar_t(&str)[n]) {
149 assert(_str[n - 1] ==
'\0',
"Invalid NTBS.");
150 _str = str, _size = n - 1, _const =
false;
156 constexpr wcstring& operator=(
const wchar_t(&str)[n]) {
157 assert(str[n - 1] ==
'\0',
"Invalid NTBS.");
158 _cstr = str; _size = n - 1; _const =
true;
164 _cstr = str._cstr; str._cstr =
nullptr;
165 _size = str._size; str._size = 0;
166 _const = str._const; str._const =
true;
175 constexpr size_t size()
const {
return _size; }
179 constexpr size_t capacity()
const {
return _size + 1; }
181 constexpr bool empty()
const {
182 return _cstr ==
nullptr || _size == 0;
193 assertd(not _const,
"Attempted to Access Const-Qualified Memory as Non-Const");
194 assertd(i <
size(),
"Array Out of Bounds");
203 assertd(i <
size(),
"Array Out of Bounds");
217 constexpr const wchar_t*
data()
const {
223 constexpr operator const wchar_t*()
const {
248 n =
min(n,
max(_size, str._size) + 1);
249 return ::wcsncmp(_cstr + i, str, n);
274 constexpr size_t find(
wchar_t c,
size_t i = 0)
const {
279 const wchar_t* loc = ::wcschr(_cstr + i, c);
280 return loc ? loc - _cstr : _size;
289 if (i + str._size > _size) {
293 const wchar_t* loc = ::wcsstr(_cstr + i, str);
294 return loc ? loc - _cstr : _size;
302 constexpr size_t rfind(
char c,
size_t i = npos)
const {
307 i =
min(i, _size - 1);
309 if (_cstr[i] == c)
return i;
324 const char first = str[0];
325 i =
min(i, _size - str._size);
327 if(_cstr[i] == first) {
328 if (
compare(str, i, str._size - 1) == 0) {
339 const wchar_t* _cstr;
346struct hash<wcstring> : hash<byte_array> {
347 constexpr size_t operator()(
const wcstring& str)
const {
348 return hash<byte_array>::operator()(byte_array(str, str.size()));
constexpr genType min(genType x, genType y)
Returns if otherwise it returns .
Definition common.h:688
constexpr genType max(genType x, genType y)
Returns if , otherwise it returns .
Definition common.h:705
This struct wraps c-style strings.
Definition wcstring.h:60
constexpr size_t rfind(const wcstring &str, size_t i=npos) const
Finds the index of the last occurrence of str in the string.
Definition wcstring.h:319
constexpr wcstring(wchar_t *str, size_t n)
Buffer Constructor, wraps the provided C-Style string.
Definition wcstring.h:83
constexpr bool operator==(const wchar_t(&str)[n]) const
String Equality.
Definition wcstring.h:257
constexpr size_t capacity() const
Definition wcstring.h:179
constexpr wcstring()
Default Constructor, initializes with nullptr.
Definition wcstring.h:69
constexpr wcstring(const wchar_t *str, size_t n)
Const Buffer Constructor, wraps the provided C-Style string.
Definition wcstring.h:106
constexpr bool operator==(const wcstring &str) const
String Equality.
Definition wcstring.h:265
constexpr const wchar_t * data() const
Data Access.
Definition wcstring.h:217
constexpr wcstring(const wchar_t(&str)[n])
Buffer Constructor, wraps the provided C-Style string.
Definition wcstring.h:118
constexpr size_t find(wchar_t c, size_t i=0) const
Finds the index of the first occurrence of c in the string.
Definition wcstring.h:274
constexpr wcstring(wchar_t(&str)[n])
Buffer Constructor, wraps the provided C-Style string.
Definition wcstring.h:95
constexpr size_t find(const wcstring &str, size_t i=0) const
Finds the index of the first occurrence of str in the string.
Definition wcstring.h:288
constexpr wcstring(wcstring &&str) noexcept
Move Constructor.
Definition wcstring.h:128
constexpr size_t size() const
Definition wcstring.h:175
constexpr wchar_t * data()
Data Access.
Definition wcstring.h:210
constexpr int compare(const wcstring &str, size_t i=0, size_t n=npos) const
String Comparison.
Definition wcstring.h:243
constexpr const wchar_t & operator[](size_t i) const
Const-Array Access Operator.
Definition wcstring.h:202
constexpr wcstring(nullptr_t)
Default Constructor, initializes with nullptr.
Definition wcstring.h:75
constexpr size_t length() const
Definition wcstring.h:232
constexpr wchar_t & operator[](size_t i)
Array Access Operator.
Definition wcstring.h:192
constexpr size_t rfind(char c, size_t i=npos) const
Finds the index of the last occurrence of c in the string.
Definition wcstring.h:302
decltype(nullptr) nullptr_t
Null Pointer Type.
Definition types.h:245