mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
#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());
|
|
}
|
|
|
|
}
|