20 #include "pedigree/kernel/compiler.h" 21 #include "pedigree/kernel/processor/types.h" 22 #include "pedigree/kernel/utilities/Cord.h" 23 #include "pedigree/kernel/utilities/String.h" 24 #include "pedigree/kernel/utilities/List.h" 26 Cord::Cord() =
default;
28 Cord::Cord(
const Cord &other) :
Cord()
46 m_Segments.reserve(segments,
true);
49 void Cord::assign(
const Cord &other)
53 m_Segments.reserve(other.m_Segments.count(),
false);
55 for (
auto &it : other.m_Segments)
57 m_Segments.pushBack(it);
58 m_Length += it.length;
64 m_Segments.clear(
false);
67 size_t Cord::length()
const 72 String Cord::toString()
const 74 char *buf =
new char[m_Length + 1];
76 for (
auto &it : m_Segments)
78 MemoryCopy(buf + offset, it.ptr, it.length);
84 String result(buf, m_Length);
92 for (
auto &it : m_Segments)
94 if ((index >= i) && (index < (i + it.length)))
96 return it.ptr[index - i];
106 void Cord::append(
const char *s,
size_t len)
110 len = StringLength(s);
117 void Cord::prepend(
const char *s,
size_t len)
121 len = StringLength(s);
138 Cord::CordIterator::CordIterator(
const Cord &owner) : cord(owner), segment(0), index(0)
142 Cord::CordIterator::CordIterator(
const Cord &owner,
bool end) : cord(owner), segment(0), index(0)
144 segment = owner.m_Segments.count();
147 Cord::CordIterator::~CordIterator() =
default;
152 if (index >= cord.m_Segments[segment].length)
158 if (segment > cord.m_Segments.count())
160 segment = cord.m_Segments.count();
176 index = cord.m_Segments[segment].length;
182 char Cord::CordIterator::operator*()
const 184 return cord.m_Segments[segment].ptr[index];
187 bool Cord::CordIterator::operator==(
const CordIterator &other)
const 189 return segment == other.segment && index == other.index;
192 bool Cord::CordIterator::operator!=(
const CordIterator &other)
const 194 return !(*
this == other);
char operator[](size_t index) const
void reserve(size_t segments)