mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
Import all this stuff into a single repo called Serenity.
This commit is contained in:
commit
5a30055157
67 changed files with 8836 additions and 0 deletions
56
AK/String.cpp
Normal file
56
AK/String.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "String.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace AK {
|
||||
|
||||
bool String::operator==(const String& other) const
|
||||
{
|
||||
if (!m_impl)
|
||||
return !other.m_impl;
|
||||
|
||||
if (!other.m_impl)
|
||||
return false;
|
||||
|
||||
if (length() != other.length())
|
||||
return false;
|
||||
|
||||
return !memcmp(characters(), other.characters(), length());
|
||||
}
|
||||
|
||||
String String::empty()
|
||||
{
|
||||
return StringImpl::theEmptyStringImpl();
|
||||
}
|
||||
|
||||
Vector<String> String::split(const char separator) const
|
||||
{
|
||||
if (isEmpty())
|
||||
return { };
|
||||
|
||||
Vector<String> parts;
|
||||
|
||||
auto* characters = this->characters();
|
||||
unsigned startOfPart = 0;
|
||||
unsigned i = 0;
|
||||
for (i = 0; i < length(); ++i) {
|
||||
char ch = characters[i];
|
||||
if (ch == separator) {
|
||||
if (i != startOfPart) {
|
||||
parts.append(String(characters + startOfPart, i - startOfPart));
|
||||
}
|
||||
startOfPart = i + 1;
|
||||
}
|
||||
}
|
||||
if (startOfPart != length())
|
||||
parts.append(String(characters + startOfPart, i - startOfPart));
|
||||
return parts;
|
||||
}
|
||||
|
||||
ByteBuffer String::toByteBuffer() const
|
||||
{
|
||||
if (!m_impl)
|
||||
return nullptr;
|
||||
return ByteBuffer::copy(reinterpret_cast<const byte*>(characters()), length());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue