mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +00:00
AK: Reduce header dependency graph of String.h
String.h no longer pulls in StringView.h. We do this by moving a bunch of String functions out-of-line.
This commit is contained in:
parent
1dd71bd68f
commit
7d862dd5fc
39 changed files with 122 additions and 77 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
#ifndef KERNEL
|
||||
|
@ -41,6 +42,14 @@ extern "C" char* strstr(const char* haystack, const char* needle);
|
|||
|
||||
namespace AK {
|
||||
|
||||
String::String(const StringView& view)
|
||||
{
|
||||
if (view.m_impl)
|
||||
m_impl = *view.m_impl;
|
||||
else
|
||||
m_impl = StringImpl::create(view.characters_without_null_termination(), view.length());
|
||||
}
|
||||
|
||||
bool String::operator==(const String& other) const
|
||||
{
|
||||
if (!m_impl)
|
||||
|
@ -341,4 +350,50 @@ String String::to_uppercase() const
|
|||
return m_impl->to_uppercase();
|
||||
}
|
||||
|
||||
bool operator<(const char* characters, const String& string)
|
||||
{
|
||||
if (!characters)
|
||||
return !string.is_null();
|
||||
|
||||
if (string.is_null())
|
||||
return false;
|
||||
|
||||
return __builtin_strcmp(characters, string.characters()) < 0;
|
||||
}
|
||||
|
||||
bool operator>=(const char* characters, const String& string)
|
||||
{
|
||||
return !(characters < string);
|
||||
}
|
||||
|
||||
bool operator>(const char* characters, const String& string)
|
||||
{
|
||||
if (!characters)
|
||||
return !string.is_null();
|
||||
|
||||
if (string.is_null())
|
||||
return false;
|
||||
|
||||
return __builtin_strcmp(characters, string.characters()) > 0;
|
||||
}
|
||||
|
||||
bool operator<=(const char* characters, const String& string)
|
||||
{
|
||||
return !(characters > string);
|
||||
}
|
||||
|
||||
bool String::operator==(const char* cstring) const
|
||||
{
|
||||
if (is_null())
|
||||
return !cstring;
|
||||
if (!cstring)
|
||||
return false;
|
||||
return !__builtin_strcmp(characters(), cstring);
|
||||
}
|
||||
|
||||
StringView String::view() const
|
||||
{
|
||||
return { characters(), length() };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue