blob: b52a252277b8a8a8c8c5e287a2ba24a9093c19a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#pragma once
#include "Retainable.h"
#include "RetainPtr.h"
#include "Types.h"
namespace AK {
class StringImpl : public Retainable<StringImpl> {
public:
static RetainPtr<StringImpl> createUninitialized(size_t 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();
static void initializeGlobals();
~StringImpl();
size_t length() const { return m_length; }
const char* characters() const { return m_characters; }
char operator[](size_t 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, size_t length) : m_length(length), m_characters(m_inlineBuffer) { }
void computeHash() const;
size_t 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;
|