1/* 2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef STRING_H 6#define STRING_H 7 8 9#include "StringPool.h" 10 11 12class String { 13public: 14 String(); 15 String(const String& other); 16 ~String(); 17 18 bool SetTo(const char* string); 19 bool SetTo(const char* string, size_t maxLength); 20 bool SetToExactLength(const char* string, 21 size_t length); 22 23 const char* Data() const; 24 uint32 Hash() const; 25 26 bool IsEmpty() const; 27 28 String& operator=(const String& other); 29 30 bool operator==(const String& other) const; 31 bool operator!=(const String& other) const; 32 33 operator const char*() const; 34 35private: 36 StringData* fData; 37}; 38 39 40inline 41String::String() 42 : 43 fData(StringData::GetEmpty()) 44{ 45} 46 47 48inline 49String::String(const String& other) 50 : 51 fData(other.fData) 52{ 53 fData->AcquireReference(); 54} 55 56 57inline 58String::~String() 59{ 60 fData->ReleaseReference(); 61} 62 63 64inline bool 65String::SetTo(const char* string) 66{ 67 return SetToExactLength(string, (string == NULL) ? 0 : strlen(string)); 68} 69 70 71inline bool 72String::SetTo(const char* string, size_t maxLength) 73{ 74 return SetToExactLength(string, strnlen(string, maxLength)); 75} 76 77 78inline const char* 79String::Data() const 80{ 81 return fData->String(); 82} 83 84 85inline uint32 86String::Hash() const 87{ 88 return fData->Hash(); 89} 90 91 92inline bool 93String::IsEmpty() const 94{ 95 return fData == StringData::Empty(); 96} 97 98 99inline bool 100String::operator==(const String& other) const 101{ 102 return fData == other.fData; 103} 104 105 106inline bool 107String::operator!=(const String& other) const 108{ 109 return !(*this == other); 110} 111 112 113inline 114String::operator const char*() const 115{ 116 return fData->String(); 117} 118 119 120#endif // STRING_H 121