1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:57:35 +00:00

Import all this stuff into a single repo called Serenity.

This commit is contained in:
Andreas Kling 2018-10-10 11:53:07 +02:00
commit 5a30055157
67 changed files with 8836 additions and 0 deletions

50
AK/StringImpl.h Normal file
View file

@ -0,0 +1,50 @@
#pragma once
#include "Retainable.h"
#include "RetainPtr.h"
namespace AK {
class StringImpl : public Retainable<StringImpl> {
public:
static RetainPtr<StringImpl> createUninitialized(unsigned length, char*& buffer);
static RetainPtr<StringImpl> create(const char* cstring);
static RetainPtr<StringImpl> create(const char* cstring, size_t length);
RetainPtr<StringImpl> toLowercase() const;
RetainPtr<StringImpl> toUppercase() const;
static StringImpl& theEmptyStringImpl();
~StringImpl();
unsigned length() const { return m_length; }
const char* characters() const { return m_characters; }
char operator[](unsigned i) const { ASSERT(i < m_length); return m_characters[i]; }
unsigned hash() const
{
if (!m_hasHash)
computeHash();
return m_hash;
}
private:
enum ConstructTheEmptyStringImplTag { ConstructTheEmptyStringImpl };
explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { }
enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer };
explicit StringImpl(ConstructWithInlineBufferTag, unsigned length) : m_length(length), m_characters(m_inlineBuffer) { }
void computeHash() const;
unsigned m_length { 0 };
bool m_ownsBuffer { true };
mutable bool m_hasHash { false };
const char* m_characters { nullptr };
mutable unsigned m_hash { 0 };
char m_inlineBuffer[0];
};
}
using AK::StringImpl;