wavelength 1.0.0
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1#pragma once
2
3#include "os/prnstream.h"
4
11extern char *g_szStringEmptyBuffer;
12
19class String : public PrnStream {
20public:
26 String() : mLength(0), mBuffer(g_szStringEmptyBuffer) {
27 }
28
36 explicit String(const char *pszText);
37
45 String(const String &other);
46
53 ~String() override;
54
62 void Print(const char *pszText) override;
63
74 String &operator=(const String &other);
75
84 String &operator=(const char *pszText);
85
96
105 char operator[](int nIndex) const;
106
117 String &Replace(int nPos, int nCount, const String &text);
118
129 String &Truncate(int nLength);
130
142 String &Erase(int nPos, int nCount);
143
152 String &operator+=(const String &other);
153
162 String &operator+=(const char *pszText);
163
173
184 int Compare(int nPos, int nCount, const char *pszText) const;
185
187 static constexpr int npos = -1;
188
197 int Find(const char *pszText) const;
198
207 int Find(char ch) const;
208
218 int Find(char ch, int nPos) const;
219
228 int RFind(char ch) const;
229
238 String Substring(int nPos) const;
239
250 String Substring(int nPos, int nCount) const;
251
262 String &Insert(int nPos, int nCount, char ch);
263
273 String &Insert(int nPos, const String &text);
274
283 bool operator<(const String &other) const;
284
293 bool operator==(const char *pszText) const;
294
303 bool operator==(const String &other) const;
304
313 bool operator!=(const char *pszText) const;
314
323 bool operator!=(const String &other) const;
324
333 String operator+(const char *pszText) const;
334
343 String operator+(char ch) const;
344
353 String operator+(const String &other) const;
354
362 void Resize(int nLength);
363
369 const char *c_str() const {
370 return mBuffer;
371 }
372
374 int GetLength() const {
375 return mLength;
376 }
377
379 char *GetBuffer() const {
380 return mBuffer;
381 }
382
383private:
384 int mLength;
385 int mCapacity;
386 char *mBuffer;
387};
388
399const char *FormatString(const char *pszFormat, ...);
400
411void SetStringReadsText(int bText);
PrnStream()
Construct a stream with a dump level of 0.
Definition prnstream.h:23
String & Replace(int nPos, int nCount, const String &text)
Replace a run of characters with another string's text.
bool operator!=(const char *pszText) const
Report whether the text differs from a C string.
int GetLength() const
Definition string.h:374
int Find(const char *pszText) const
Find the first occurrence of a C string in the text.
String & operator+=(const char *pszText)
Append a C string.
char operator[](int nIndex) const
Report one character.
static constexpr int npos
The position Find() reports when the text does not occur.
Definition string.h:187
bool operator==(const String &other) const
Report whether the text equals another string's text.
String operator+(const char *pszText) const
Report a copy of the string with text appended.
String & operator=(const char *pszText)
Replace the text with a copy of a C string.
String & operator+=(char ch)
Append a character.
String & Insert(int nPos, const String &text)
Insert a copy of another string's text.
void Resize(int nLength)
Replace the text with nLength zero bytes.
String & Clear()
Release the text and leave the string empty.
String & operator=(const String &other)
Replace the text with a copy of another string's text.
void Print(const char *pszText) override
Append text.
int RFind(char ch) const
Find the last occurrence of a character.
int Find(char ch) const
Find the first occurrence of a character.
String()
Construct an empty string.
Definition string.h:26
const char * c_str() const
Report the text.
Definition string.h:369
int Find(char ch, int nPos) const
Find the first occurrence of a character at or after a position.
bool operator==(const char *pszText) const
Report whether the text equals a C string.
String Substring(int nPos, int nCount) const
Copy a run of characters, or the characters from a position to the end when the run reaches the end.
~String() override
Release the text.
char * GetBuffer() const
Definition string.h:379
bool operator<(const String &other) const
Report whether the text sorts before another string's text.
String & operator+=(const String &other)
Append another string's text.
String operator+(const String &other) const
Report a copy of the string with another string's text appended.
String & Erase(int nPos, int nCount)
Remove a run of characters.
String(const char *pszText)
Construct a copy of a C string.
bool operator!=(const String &other) const
Report whether the text differs from another string's text.
String & Truncate(int nLength)
Cut the text to a length.
String Substring(int nPos) const
Copy the characters from a position to the end.
int Compare(int nPos, int nCount, const char *pszText) const
Compare a run of characters with a C string.
String & Insert(int nPos, int nCount, char ch)
Insert copies of one character.
String operator+(char ch) const
Report a copy of the string with a character appended.
String(const String &other)
Copy another string.
void SetStringReadsText(int bText)
Make operator>>(BinStream &, String &) read text up to its terminator, or read a string as BinStream:...
char * g_szStringEmptyBuffer
Shared terminated buffer every empty String points at.
const char * FormatString(const char *pszFormat,...)
Format text into one shared buffer and return it.