20#ifndef KERNEL_UTILITIES_STRING_H
21#define KERNEL_UTILITIES_STRING_H
26#include "pedigree/kernel/compiler.h"
27#include "pedigree/kernel/processor/types.h"
28#include "pedigree/kernel/utilities/StringView.h"
29#include "pedigree/kernel/utilities/Vector.h"
30#include "pedigree/kernel/utilities/template.h"
33#ifdef IN_STRING_TESTSUITE
34#define STRING_DISABLE_EXPENSIVE_COPY_CONSTRUCTION 0
36#define STRING_DISABLE_EXPENSIVE_COPY_CONSTRUCTION 1
50 explicit String(
const char* s);
51 explicit String(
const char* s,
size_t length);
52 explicit String(
const char* s,
size_t length,
bool unsafe);
62#if STRING_DISABLE_EXPENSIVE_COPY_CONSTRUCTION
63 String& operator=(
const char* s) =
delete;
65 String& operator=(
const char* s);
71 explicit operator const char*()
const {
80 String& operator+=(
const char* s);
87 bool compare(
const char* s,
size_t len)
const;
98 return compare(s, N - 1);
101 char operator[](
size_t i)
const;
103 const char* cstr()
const {
107 size_t length()
const {
111 size_t size()
const {
119 uint32_t hash()
const;
126 size_t nextCharacter(
size_t c)
const;
130 size_t prevCharacter(
size_t c)
const;
148 void ltrim(
size_t n);
151 void rtrim(
size_t n);
156 String split(
size_t offset);
157 void split(
size_t offset,
String& back);
168 static size_t Utf32ToUtf8(uint32_t utf32,
char* utf8);
170 void Format(
const char* format, ...)
FORMAT(printf, 2, 3);
173 void assign(const
char (&s)[N]) {
177 void assign(
const String& x);
178 void assign(
const Cord& x);
185 void assign(
const char* s,
size_t len = 0,
bool unsafe =
false);
186 void reserve(
size_t size);
187 virtual void clear() noexcept;
193 bool endswith(const
char c) const;
194 bool endswith(const
String& s) const;
195 bool endswith(const
char* s,
size_t len = 0) const;
198 bool startswith(const
char c) const;
199 bool startswith(const
String& s) const;
200 bool startswith(const
char* s,
size_t len = 0) const;
203 ssize_t find(const
char c) const;
204 ssize_t rfind(const
char c) const;
216 bool iswhitespace(const
char c) const;
218 void reserve(
size_t size,
bool zero);
222 uint32_t computeHash() const;
226 uint32_t maybeHash() const;
228 virtual
char* extract() const;
230 void move(
String&& other) noexcept;
240 virtual
bool resizable() const;
242 virtual
bool assignable() const;
246 void setLength(
size_t n);
248 void setSize(
size_t n);
262 MemoryCopy(m_Data, str, N);
266 virtual void clear()
noexcept override {}
270 return const_cast<char*
>(m_Data);
virtual char * extract() const override
virtual bool assignable() const override
virtual bool resizable() const override
bool compare(const char(&s)[N]) const
A vector / dynamic array.
#define FORMAT(type, idx, first)
bool operator==(const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T1 > &x1, const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T2 > &x2)