20 #include "pedigree/kernel/utilities/String.h" 21 #include "pedigree/kernel/Log.h" 22 #include "pedigree/kernel/utilities/StringView.h" 23 #include "pedigree/kernel/utilities/assert.h" 24 #include "pedigree/kernel/utilities/utility.h" 28 : m_Data(0), m_ConstData(nullptr), m_Length(0), m_Size(StaticSize),
29 m_HeapData(true), m_Hash(0)
44 #if !STRING_DISABLE_COPY_CONSTRUCTION 53 move(pedigree_std::move(x));
64 m_Data = pedigree_std::move(other.m_Data);
65 m_ConstData = pedigree_std::move(other.m_ConstData);
66 m_Length = pedigree_std::move(other.m_Length);
67 m_Size = pedigree_std::move(other.m_Size);
68 m_HeapData = pedigree_std::move(other.m_HeapData);
69 m_Hash = pedigree_std::move(other.m_Hash);
83 move(pedigree_std::move(x));
87 #if !STRING_DISABLE_COPY_CONSTRUCTION 94 String &String::operator=(
const char *s)
109 size_t newLength = x.length() +
m_Length;
116 reserve(newLength + 1);
127 MemoryCopy(&dst[
m_Length], src, x.length() + 1);
128 m_Length += x.length();
130 #if STRING_DISABLE_JIT_HASHING 136 String &String::operator+=(
const char *s)
144 size_t slen = StringLength(s);
151 MemoryCopy(&
m_Static[m_Length], s, slen + 1);
155 reserve(slen + m_Length + 1);
158 MemoryCopy(&
m_Data[m_Length], s, slen + 1);
163 #if STRING_DISABLE_JIT_HASHING 169 bool String::operator==(
const String &s)
const 182 const char *other_buf = s.
extract();
185 return !StringMatchN(buf, other_buf,
m_Length + 1);
188 bool String::operator==(
const StringView &s)
const 194 bool String::operator==(
const char *s)
const 214 return StringMatchN(buf, s,
m_Length + 1) == 0;
241 return ::nextCharacter(buf, c);
247 return ::prevCharacter(buf, c);
250 void String::assign(
const String &x)
277 #ifdef ADDITIONAL_CHECKS 280 ERROR(
"mismatch: '" << *
this <<
"' != '" << x <<
"'");
290 void String::assign(
const char *s,
size_t len,
bool unsafe)
292 size_t copyLength = 0;
300 size_t trueLength = StringLength(s);
301 if (trueLength < len)
331 MemoryCopy(
m_Static, s, copyLength);
343 MemoryCopy(
m_Data, s, copyLength);
344 m_Data[copyLength] =
'\0';
350 #ifdef ADDITIONAL_CHECKS 358 #if STRING_DISABLE_JIT_HASHING 363 void String::reserve(
size_t size)
368 void String::reserve(
size_t size,
bool zero)
421 split(offset, result);
435 back.assign(&buf[offset]);
455 #if STRING_DISABLE_JIT_HASHING 480 MemoryCopy(buf, (buf + n),
m_Length);
496 #if STRING_DISABLE_JIT_HASHING 531 #if STRING_DISABLE_JIT_HASHING 539 tokenise(token, list);
551 utf8[0] = utf32 & 0x7F;
554 else if (utf32 <= 0x7FF)
556 utf8[0] = 0xC0 | ((utf32 >> 6) & 0x1F);
557 utf8[1] = 0x80 | (utf32 & 0x3F);
560 else if (utf32 <= 0xFFFF)
562 utf8[0] = 0xE0 | ((utf32 >> 12) & 0x0F);
563 utf8[1] = 0x80 | ((utf32 >> 6) & 0x3F);
564 utf8[2] = 0x80 | (utf32 & 0x3F);
567 else if (utf32 <= 0x10FFFF)
569 utf8[0] = 0xF0 | ((utf32 >> 18) & 0x07);
570 utf8[1] = 0x80 | ((utf32 >> 12) & 0x3F);
571 utf8[2] = 0x80 | ((utf32 >> 6) & 0x3F);
572 utf8[3] = 0x80 | (utf32 & 0x3F);
581 const char *orig_buffer =
extract();
582 const char *buffer = orig_buffer;
586 const char *pos = buffer ? StringFind(buffer, token) :
nullptr;
587 while (pos && (*buffer))
602 pos = StringFind(buffer, token);
608 if (buffer == orig_buffer)
614 size_t length =
m_Length - (buffer - orig_buffer);
626 tokenise(token, views);
629 for (
auto &it : views)
639 StringCopy(buf, &buf[1]);
655 #if STRING_DISABLE_JIT_HASHING 680 #if STRING_DISABLE_JIT_HASHING 685 void String::Format(
const char *fmt, ...)
705 #if STRING_DISABLE_JIT_HASHING 727 const char *otherbuf = s.
extract();
728 return endswith(otherbuf, s.length());
735 len = StringLength(s);
745 return !MemoryCompare(mybuf, s, len);
765 const char *otherbuf = s.
extract();
773 len = StringLength(s);
783 return !MemoryCompare(mybuf, s, len);
788 return (c <=
' ' || c ==
'\x7f');
802 return const_cast<char *
>(
m_Static);
821 for (ssize_t i = 0; i < signedLength; ++i)
832 ssize_t String::rfind(
const char c)
const 838 for (ssize_t i =
m_Length - 1, n = 0; i >= 0; --i, ++n)
876 result.assign(*
this);
877 return pedigree_std::move(result);
void pushBack(const T &value)
String split(size_t offset)
A vector / dynamic array.
bool iswhitespace(const char c) const
static constexpr const size_t StaticSize
size_t nextCharacter(size_t c) const
char m_Static[StaticSize]
size_t prevCharacter(size_t c) const
ssize_t find(const char c) const
static size_t Utf32ToUtf8(uint32_t utf32, char *utf8)
void clear(bool freeMem=false)
void move(String &&other)
bool endswith(const char c) const
bool startswith(const char c) const