-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoubleNullStr.h
More file actions
154 lines (121 loc) · 5.37 KB
/
Copy pathDoubleNullStr.h
File metadata and controls
154 lines (121 loc) · 5.37 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#pragma once
NS_BEGIN
constexpr PCSTR g_szDoubleNull8 = "\0\0";
constexpr PCWSTR g_szDoubleNullW = L"\0\0";
// Forward declarations
class CDoubleNullStr8;
class CDoubleNullStrW;
//#################################################################################################
class CDoubleNullStr8 final
{
public:
// Constructs an empty string object
CDoubleNullStr8(void) = default;
// Copy and move constructors
CDoubleNullStr8(const CDoubleNullStr8 &src);
CDoubleNullStr8(CDoubleNullStr8 &&src) noexcept;
// Constructs a string object set to the string, which can be already double null terminated
explicit CDoubleNullStr8(PCSTR sz, const bool bDoubleNullTerm = false);
~CDoubleNullStr8(void);
// Returns the length in characters (including null-terminators)
size_t GetLength(void) const noexcept;
// Returns the size in bytes (including null-terminators)
size_t GetSize(void) const noexcept;
// Returns a pointer to the raw string data
operator PCSTR(void) const noexcept;
// Returns whether the string is empty
bool IsEmpty(void) const noexcept;
// Empties the string, freeing the memory
void Empty(void);
// Copy and move assignment operators
CDoubleNullStr8 &operator=(const CDoubleNullStr8 &src);
CDoubleNullStr8 &operator=(CDoubleNullStr8 &&src) noexcept;
// Assigns the string object to the double null string
CDoubleNullStr8 &operator=(PCSTR sz);
// Assigns the string object to the double null string
void Assign(const CDoubleNullStr8 &str);
void Assign(PCSTR sz, const bool bDoubleNullTerm = false);
// Appends the string object to the double null string
CDoubleNullStr8 &operator+=(const CDoubleNullStr8 &str);
CDoubleNullStr8 &operator+=(PCSTR sz);
// Appends the string object to the double null string
void Append(const CDoubleNullStr8 &str);
void Append(PCSTR sz, const bool bDoubleNullTerm = false);
friend std::ostream &operator<<(std::ostream &stream, const CDoubleNullStr8 &str);
// Returns the number of strings in the double null string object
size_t GetCount(void) const noexcept;
// Returns a pointer to the raw string at the given index, or null if beyond the array
PCSTR GetAt(const size_t nIndex) const;
// Returns an array of strings present in the double null string object, caller must pass to 'FreeArray' to release
PCSTR *GetArray(void) const;
// Release memory allocated by 'GetArray'
static void FreeArray(PVOID szArr);
// Returns the length of the buffer in characters
size_t GetBufferLength(void) const noexcept;
// Returns the size of the buffer in bytes
size_t GetBufferSize(void) const noexcept;
private:
PSTR m_szBuffer = (PSTR)g_szDoubleNull8;
size_t m_nBufLen = 2;
size_t m_nCount = 0;
};
//#################################################################################################
class CDoubleNullStrW final
{
public:
// Constructs an empty string object
CDoubleNullStrW(void) = default;
// Copy and move constructors
CDoubleNullStrW(const CDoubleNullStrW &src);
CDoubleNullStrW(CDoubleNullStrW &&src) noexcept;
// Constructs a string object set to the string, which can be already double null terminated
explicit CDoubleNullStrW(PCWSTR sz, const bool bDoubleNullTerm = false);
~CDoubleNullStrW(void);
// Returns the length in characters (including null-terminators)
size_t GetLength(void) const noexcept;
// Returns the size in bytes (including null-terminators)
size_t GetSize(void) const noexcept;
// Returns a pointer to the raw string data
operator PCWSTR(void) const noexcept;
// Returns whether the string is empty
bool IsEmpty(void) const noexcept;
// Empties the string, freeing the memory
void Empty(void);
// Copy and move assignment operators
CDoubleNullStrW &operator=(const CDoubleNullStrW &src);
CDoubleNullStrW &operator=(CDoubleNullStrW &&src) noexcept;
// Assigns the string object to the double null string
CDoubleNullStrW &operator=(PCWSTR sz);
// Assigns the string object to the double null string
void Assign(const CDoubleNullStrW &str);
void Assign(PCWSTR sz, const bool bDoubleNullTerm = false);
// Appends the string object to the double null string
CDoubleNullStrW &operator+=(const CDoubleNullStrW &str);
CDoubleNullStrW &operator+=(PCWSTR sz);
// Appends the string object to the double null string
void Append(const CDoubleNullStrW &str);
void Append(PCWSTR sz, const bool bDoubleNullTerm = false);
friend std::wostream &operator<<(std::wostream &stream, const CDoubleNullStrW &str);
// Returns the number of strings in the double null string object
size_t GetCount(void) const noexcept;
// Returns a pointer to the raw string at the given index, or null if beyond the array
PCWSTR GetAt(const size_t nIndex) const;
// Returns an array of strings present in the double null string object, caller must pass to 'FreeArray' to release
PCWSTR *GetArray(void) const;
// Release memory allocated by 'GetArray'
static void FreeArray(PVOID pszArr);
// Returns the length of the buffer in characters
size_t GetBufferLength(void) const noexcept;
// Returns the size of the buffer in bytes
size_t GetBufferSize(void) const noexcept;
private:
PWSTR m_szBuffer = (PWSTR)g_szDoubleNullW;
size_t m_nBufLen = 2;
size_t m_nCount = 0;
};
#ifdef _WIN32
using CDoubleNullStr = CDoubleNullStrW;
#else
using CDoubleNullStr = CDoubleNullStr8;
#endif
NS_END