wavelength 1.0.0
Loading...
Searching...
No Matches
Str.h
Go to the documentation of this file.
1#pragma once
2
3#include "utl/PrnStream.h"
4
10extern char *gStringEmptyBuffer;
11
20char *FormatString(const char *format, ...);
21
31class String : public PrnStream {
32public:
34 enum { npos = -1 };
35
36 String() : mLen(0), mBuffer(gStringEmptyBuffer) {
37 }
38
45 String(const char *str);
46
53 String(const String &other);
54
60 virtual ~String();
61
68 virtual void Print(const char *str);
69
77 String &operator+=(const String &other);
78
86 String &operator+=(const char *str);
87
95 String &operator=(const char *str);
96
104 String &operator=(const String &other);
105
113 bool operator!=(const char *str) const;
114
122 bool operator!=(const String &other) const;
123
131 bool operator==(const char *str) const;
132
140 bool operator==(const String &other) const;
141
149 bool operator<(const String &other) const;
150
157 void Resize(unsigned int length);
158
166 int Find(const char *str) const;
167
175 int FindLast(char c) const;
176
184 String Substring(unsigned int pos) const;
185
194 String Substring(unsigned int pos, unsigned int count) const;
195
205 String &Replace(unsigned int pos, unsigned int count, const String &str);
206
214
216 const char *c_str() const {
217 return mBuffer;
218 }
219
221 operator const char *() const {
222 return c_str();
223 }
224
226 unsigned int size() const {
227 return mLen;
228 }
229
230private:
231 friend class BinStream;
232
233 unsigned int mLen;
234 unsigned int mCapacity;
235 char *mBuffer;
236};
char * gStringEmptyBuffer
The shared terminator of every empty String.
char * FormatString(const char *format,...)
Format text with printf() conventions into a static buffer.
Text output stream.
Definition prnstream.h:16
Growable text buffer that is also a PrnStream.
Definition string.h:19
String & Replace(unsigned int pos, unsigned int count, const String &str)
Replace part of the text with another String.
static constexpr int npos
The position Find() reports when the text does not occur.
Definition string.h:187
bool operator==(const String &other) const
Compare with another String.
friend class BinStream
Definition Str.h:231
String(const char *str)
Copy text.
unsigned int size() const
Definition Str.h:226
String & operator+=(const char *str)
Append text.
String & Clear()
Empty the String.
String & operator=(const String &other)
Replace the text with a copy of another String.
void Resize(unsigned int length)
Replace the text with a length of zero bytes.
int FindLast(char c) const
Find the last occurrence of a character.
bool operator==(const char *str) const
Compare with text.
String()
Definition Str.h:36
const char * c_str() const
Definition Str.h:216
int Find(const char *str) const
Find the first occurrence of text.
String Substring(unsigned int pos) const
Copy the text from a position to the end.
virtual void Print(const char *str)
Append printed text.
bool operator<(const String &other) const
Order by the bytes of the text.
String & operator+=(const String &other)
Append another String.
virtual ~String()
Free the buffer.
String & operator=(const char *str)
Replace the text.
String Substring(unsigned int pos, unsigned int count) const
Copy part of the text.
bool operator!=(const String &other) const
Compare with another String.
bool operator!=(const char *str) const
Compare with text.
String(const String &other)
Copy another String.