-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString.h
More file actions
117 lines (93 loc) · 3.09 KB
/
String.h
File metadata and controls
117 lines (93 loc) · 3.09 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef STRING_H
#define STRING_H
#include <fstream>
#ifdef USE_SPLIT
#include "Array.hpp"
#endif
class String
{
// Taken and modified from: https://pvs-studio.com/en/blog/terms/6658/
union
{
struct
{
char *m_data;
size_t m_size;
} m_heapBuffer;
char m_stackBuffer[sizeof(m_heapBuffer)];
} m_data;
static const int CAPACITY_PADDING = sizeof(m_data) - 1;
size_t m_capacity;
void ClearStaticArray();
void CopyFrom(const String &other);
void MoveFrom(String&& other);
void Free();
void Resize(size_t newCapacity);
void SetData(const char *str);
explicit String(size_t capacity);
public:
String();
String(const char *str);
String(const String ©);
String(String&& other);
~String();
String &operator=(const String &other);
String& operator=(String&& other);
char operator[](size_t idx) const;
char &operator[](size_t idx);
size_t GetCapacity() const;
size_t GetSize() const;
bool IsSSO() const;
void Append(const String &str);
void Append(String &&str);
void Append(char ch);
void Append(uint64_t number);
void Append(int64_t number);
void Append(uint32_t number);
void Append(int32_t number);
void Append(uint16_t number);
void Append(int16_t number);
void Append(uint8_t number);
void Append(int8_t number);
void Append(double number);
bool Contains(char ch) const;
size_t AmountOf(char ch) const;
#ifdef USE_SPLIT
Array<String> Split(char ch) const;
#endif
bool operator==(const String &rhs) const;
bool operator!=(const String &rhs) const;
friend std::ostream &operator<<(std::ostream &os, const String &str);
friend std::istream &operator>>(std::istream &is, String &str);
String &operator+=(const String &rhs);
String &operator+=(uint64_t rhs);
String &operator+=(int64_t rhs);
String &operator+=(uint32_t rhs);
String &operator+=(int32_t rhs);
String &operator+=(uint16_t rhs);
String &operator+=(int16_t rhs);
String &operator+=(uint8_t rhs);
String &operator+=(int8_t rhs);
String &operator+=(double rhs);
bool IsEmpty() const;
void Clear();
const char *c_str() const;
static void GetLine(std::istream &istream, String *pString);
static void ReadExact(std::ifstream &ifstream, size_t amount, String *pString);
void ToLower();
void ToUpper();
bool EndsWith(const String& string) const;
};
std::ostream &operator<<(std::ostream &os, const String &str);
std::istream &operator>>(std::istream &is, String &str);
String operator+(const String &lhs, const String &rhs);
String operator+(const String &lhs, uint64_t rhs);
String operator+(const String &lhs, int64_t rhs);
String operator+(const String &lhs, uint32_t rhs);
String operator+(const String &lhs, int32_t rhs);
String operator+(const String &lhs, uint16_t rhs);
String operator+(const String &lhs, int16_t rhs);
String operator+(const String &lhs, uint8_t rhs);
String operator+(const String &lhs, int8_t rhs);
String operator+(const String &lhs, double rhs);
#endif