-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathString.hpp
48 lines (43 loc) · 1.21 KB
/
String.hpp
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
#ifndef PAQ8GEN_STRING_HPP
#define PAQ8GEN_STRING_HPP
#include "Array.hpp"
/**
* A specialized string class
*/
class String : public Array<char> {
private:
void appendIntRecursive(uint64_t x);
protected:
#ifdef NDEBUG
#define chk_consistency() ((void) 0)
#else
void chk_consistency() const {
for( uint32_t i = 0; i < size() - 1; i++ ) {
if((*this)[i] == 0 ) {
quit("Internal error - string consistency check failed (1).");
}
}
if(((*this)[size() - 1]) != 0 ) {
quit("Internal error - string consistency check failed (2).");
}
}
#endif
public:
[[nodiscard]] auto c_str() const -> const char *;
/**
* Does not include the NUL terminator
* @return length of the string
*/
[[nodiscard]] auto strsize() const -> uint64_t;
void operator=(const char *s);
void operator+=(const char *s);
void operator+=(char c);
void operator+=(uint64_t x);
auto endsWith(const char *ending) const -> bool;
void stripEnd(uint64_t count);
auto beginsWith(const char *beginning) const -> bool;
void stripStart(uint64_t count);
[[nodiscard]] auto findLast(char c) const -> int;
explicit String(const char *s = "");
};
#endif //PAQ8GEN_STRING_HPP