Builds String out of a sequence of StringView or formatting through StringFormat.
More...
#include <StringBuilder.h>
|
| template<typename T > |
| static StringBuilderFor< T > | create (T &stringOrBuffer) noexcept |
| | Creates a StringBuilder for the given string or buffer, replacing its current contents.
|
| |
| template<typename T > |
| static StringBuilderFor< T > | createForAppendingTo (T &stringOrBuffer) noexcept |
| | Creates a StringBuilder for the given string or buffer, appending to its current contents.
|
| |
| template<typename T , typename... Types> |
| static bool | format (T &buffer, StringView fmt, Types &&... args) |
| | Helper to format a StringView against args, replacing destination contents, in a single function call.
|
| |
|
|
| StringBuilder (IGrowableBuffer &ibuffer, StringEncoding encoding, Flags flags) noexcept |
| |
|
void | initWithEncoding (IGrowableBuffer &bufferT, StringEncoding stringEncoding, Flags flags) noexcept |
| |
|
|
IGrowableBuffer * | buffer = nullptr |
| |
|
StringEncoding | encoding |
| |
Builds String out of a sequence of StringView or formatting through StringFormat.
The output can be a SC::Buffer or a SC::SmallBuffer (see Foundation) One can do a:
StringBuilder::format example:
String buffer(StringEncoding::Ascii);
SC_TEST_EXPECT(StringBuilder::format(buffer,
"[{1}-{0}]",
"Storia",
"Bella"));
StringBuilder::create example:
String buffer(StringEncoding::Ascii);
auto builder = StringBuilder::create(buffer);
◆ AppendHexCase
◆ Flags
| Enumerator |
|---|
| Clear | Destination buffer will be cleared before pushing to it.
|
| Append | Destination buffer will not be cleared before pushing to it.
|
◆ append() [1/2]
template<typename... Types>
| bool SC::StringBuilder::append |
( |
StringView | fmt, |
|
|
Types &&... | args ) |
|
inlinenodiscard |
Formats the given StringView against args, appending to destination contents.
◆ append() [2/2]
Appends StringView to destination buffer.
- Parameters
-
◆ 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};
auto builder = StringBuilder::create(buffer);
SC_TEST_EXPECT(builder.appendHex({bytes, sizeof(bytes)}, StringBuilder::AppendHexCase::UpperCase));
◆ 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 |
Example:
String buffer(StringEncoding::Ascii);
{
auto builder = StringBuilder::create(buffer);
SC_TEST_EXPECT(builder.appendReplaceAll(
"123 456 123 10",
"123",
"1234"));
}
{
auto builder = StringBuilder::create(buffer);
}
◆ create()
Creates a StringBuilder for the given string or buffer, replacing its current contents.
◆ createForAppendingTo()
template<typename T >
| static StringBuilderFor< T > SC::StringBuilder::createForAppendingTo |
( |
T & | stringOrBuffer | ) |
|
|
inlinestaticnoexcept |
Creates a StringBuilder for the given string or buffer, appending to its current contents.
◆ format()
template<typename T , typename... Types>
| static bool SC::StringBuilder::format |
( |
T & | buffer, |
|
|
StringView | fmt, |
|
|
Types &&... | args ) |
|
inlinestaticnodiscard |
Helper to format a StringView against args, replacing destination contents, in a single function call.
The documentation for this struct was generated from the following file: