mirror of
https://github.com/espressif/openthread.git
synced 2026-09-14 21:20:11 +00:00
[string] change String<kSize> to inherit from StringWriter (#6658)
This commit changes the `String<kSize>` class to inherit from `StringWriter` class. It helps simplify their use allowing `StringWriter` methods to be directly called on an `String` instance while ensuring the implementation is still shared among all template variants of `String<kSize>` class. This change also ensures that `String<kSize>` is always initialized and set to an empty string from its constructor.
This commit is contained in:
@@ -212,7 +212,6 @@ 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++)
|
||||
{
|
||||
@@ -220,16 +219,16 @@ void Notifier::LogEvents(Events aEvents) const
|
||||
|
||||
if (flags & (1 << bit))
|
||||
{
|
||||
if (writer.GetLength() >= kFlagsStringLineLimit)
|
||||
if (string.GetLength() >= kFlagsStringLineLimit)
|
||||
{
|
||||
otLogInfoCore("Notifier: StateChanged (0x%08x) %s%s ...", aEvents.GetAsFlags(), didLog ? "... " : "[",
|
||||
string.AsCString());
|
||||
writer.Clear();
|
||||
string.Clear();
|
||||
didLog = true;
|
||||
addSpace = false;
|
||||
}
|
||||
|
||||
writer.Append("%s%s", addSpace ? " " : "", EventToString(static_cast<Event>(1 << bit)));
|
||||
string.Append("%s%s", addSpace ? " " : "", EventToString(static_cast<Event>(1 << bit)));
|
||||
addSpace = true;
|
||||
|
||||
flags ^= (1 << bit);
|
||||
|
||||
Reference in New Issue
Block a user