[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:
Abtin Keshavarzian
2021-05-21 12:08:26 -07:00
committed by GitHub
parent 6891fe6e0c
commit 5915483063
17 changed files with 137 additions and 176 deletions
+3 -4
View File
@@ -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);