Builds String out of a sequence of StringView or formatting through StringFormat.
More...
#include <StringBuilder.h>
|
| StringBuilder (Vector< char > &stringData, StringEncoding encoding, Flags flags=DoNotClear) |
| Create a StringBuilder that will push to given Vector, with specific encoding. More...
|
|
| StringBuilder (String &str, Flags flags=DoNotClear) |
| Create a StringBuilder that will push to given String, with specific encoding. More...
|
|
template<typename... Types> |
bool | format (StringView fmt, Types &&... args) |
| Uses StringFormat to format the given StringView against args, replacing destination contents. More...
|
|
template<typename... Types> |
bool | append (StringView fmt, Types &&... args) |
| Uses StringFormat to format the given StringView against args, appending to destination contents. More...
|
|
bool | format (StringView text) |
| Assigns StringView to destination buffer. More...
|
|
bool | append (StringView str) |
| Appends StringView to destination buffer. More...
|
|
bool | appendReplaceAll (StringView source, StringView occurrencesOf, StringView with) |
| Appends source to destination buffer, replacing occurrencesOf StringView with StringView with More...
|
|
bool | appendReplaceMultiple (StringView source, Span< const ReplacePair > substitutions) |
| Appends source to destination buffer, replacing multiple substitutions pairs. More...
|
|
bool | appendHex (Span< const uint8_t > data, AppendHexCase casing) |
| Appends given binary data escaping it as hexadecimal ASCII characters. More...
|
|
Builds String out of a sequence of StringView or formatting through StringFormat.
The output can be a SC::Vector (or a SC::SmallVector, see Containers)
◆ AppendHexCase
◆ Flags
Clearing flags used when initializing destination buffer.
Enumerator |
---|
Clear | Destination buffer will be cleared before pushing to it.
|
DoNotClear | Destination buffer will not be cleared before pushing to it.
|
◆ StringBuilder() [1/2]
Create a StringBuilder that will push to given Vector, with specific encoding.
- Parameters
-
stringData | Destination buffer where code points will be pushed |
encoding | The encoding to be used |
flags | Specifies if destination buffer must be emptied or not before pushing |
◆ StringBuilder() [2/2]
Create a StringBuilder that will push to given String, with specific encoding.
- Parameters
-
str | Destination buffer where code points will be pushed |
flags | Specifies if destination buffer must be emptied or not before pushing |
◆ append() [1/2]
template<typename... Types>
bool SC::StringBuilder::append |
( |
StringView |
fmt, |
|
|
Types &&... |
args |
|
) |
| |
|
inline |
Uses StringFormat to format the given StringView against args, appending to destination contents.
- Template Parameters
-
- Parameters
-
fmt | The format strings |
args | arguments to format |
- Returns
true
if format succeeded
Example:
SC_TRY(builder.append(
"Salve"));
SC_TRY(builder.append(
" {1} {0}!!!",
"tutti",
"a"));
#define SC_ASSERT_RELEASE(e)
Assert expression e to be true.
Definition: Assert.h:66
#define SC_TRY(expression)
Checks the value of the given expression and if failed, returns this value to caller.
Definition: Result.h:47
@ Ascii
Encoding is ASCII.
StringBuilder(Vector< char > &stringData, StringEncoding encoding, Flags flags=DoNotClear)
Create a StringBuilder that will push to given Vector, with specific encoding.
◆ append() [2/2]
Appends StringView to destination buffer.
- Parameters
-
- Returns
true
if append succeeded
◆ appendHex()
Appends given binary data escaping it as hexadecimal ASCII characters.
- Parameters
-
data | Binary data to append to destination buffer |
casing | Specifies if it should be appended using upper case or lower case |
- Returns
true
if append succeeded
Example:
uint8_t bytes[4] = {0x12, 0x34, 0x56, 0x78};
String buffer;
SC_TEST_EXPECT(builder.appendHex({bytes, sizeof(bytes)}, StringBuilder::AppendHexCase::UpperCase));
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition: PrimitiveTypes.h:36
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113
◆ appendReplaceAll()
Appends source to destination buffer, replacing occurrencesOf
StringView with StringView with
- Parameters
-
source | The StringView to be appended |
occurrencesOf | The StringView to be searched inside source |
with | The replacement StringView to be written in destination buffer |
- Returns
true
if append succeeded
Example:
SC_TEST_EXPECT(builder.appendReplaceAll(
"123 456 123 10",
"123",
"1234"));
buffer = String();
◆ appendReplaceMultiple()
Appends source to destination buffer, replacing multiple substitutions pairs.
- Parameters
-
source | The StringView to be appended |
substitutions | For each substitution in the span, the first is searched and replaced with the second. |
- Returns
true
if append succeeded
Example:
SC_TEST_EXPECT(sb.appendReplaceMultiple(
"asd\\salve\\bas"_u8, {{
"asd",
"un"}, {
"bas",
"a_tutti"}, {
"\\",
"/"}}));
◆ format() [1/2]
template<typename... Types>
bool SC::StringBuilder::format |
( |
StringView |
fmt, |
|
|
Types &&... |
args |
|
) |
| |
|
inline |
Uses StringFormat to format the given StringView against args, replacing destination contents.
- Template Parameters
-
- Parameters
-
fmt | The format strings |
args | arguments to format |
- Returns
true
if format succeeded
SC_TRY(builder.format(
"[{1}-{0}]",
"Storia",
"Bella"));
◆ format() [2/2]
Assigns StringView to destination buffer.
- Parameters
-
- Returns
true
if assign succeeded
The documentation for this struct was generated from the following file: