[string] introduce StringWriter class (#6564)

This commit moves methods of String out of the header file to save code
size.

Since most use cases of String writers ignores errors, this commit
changes the return of writers to the Writer object itself for chained
writes.
This commit is contained in:
Yakun Xu
2021-05-05 21:52:59 -07:00
committed by GitHub
parent 26cdf63231
commit b39f5b6dd2
18 changed files with 284 additions and 278 deletions
+4 -3
View File
@@ -212,6 +212,7 @@ void Notifier::LogEvents(Events aEvents) const
bool addSpace = false;
bool didLog = false;
String<kFlagsStringBufferSize> string;
StringWriter writer(string);
for (uint8_t bit = 0; bit < sizeof(Events::Flags) * CHAR_BIT; bit++)
{
@@ -219,16 +220,16 @@ void Notifier::LogEvents(Events aEvents) const
if (flags & (1 << bit))
{
if (string.GetLength() >= kFlagsStringLineLimit)
if (writer.GetLength() >= kFlagsStringLineLimit)
{
otLogInfoCore("Notifier: StateChanged (0x%08x) %s%s ...", aEvents.GetAsFlags(), didLog ? "... " : "[",
string.AsCString());
string.Clear();
writer.Clear();
didLog = true;
addSpace = false;
}
IgnoreError(string.Append("%s%s", addSpace ? " " : "", EventToString(static_cast<Event>(1 << bit))));
writer.Append("%s%s", addSpace ? " " : "", EventToString(static_cast<Event>(1 << bit)));
addSpace = true;
flags ^= (1 << bit);