mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-05-19 05:57:30 -04:00
* Changed RNG used when randomizing quotes list that was accidentally omitted in the previous PR. * Small cleanup around RandomizedQuoteModel.
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "QuotesSettingsSerializer.hpp"
|
|
#include <module-utils/utility/Utils.hpp>
|
|
|
|
namespace Quotes
|
|
{
|
|
|
|
auto QuotesSettingsSerializer::serialize(const IdList &list) -> std::string
|
|
{
|
|
std::string output;
|
|
for (const auto &[type, id] : list) {
|
|
output.append(utils::to_string(static_cast<int>(type)) + ',');
|
|
output.append(utils::to_string(id) + ',');
|
|
}
|
|
return output;
|
|
}
|
|
auto QuotesSettingsSerializer::deserialize(const std::string &listString) -> IdList
|
|
{
|
|
std::stringstream ss(listString);
|
|
IdList list;
|
|
QuoteID quoteID;
|
|
bool type = true;
|
|
for (int i; ss >> i;) {
|
|
if (type) {
|
|
quoteID.first = static_cast<QuoteType>(i);
|
|
type = false;
|
|
}
|
|
else {
|
|
quoteID.second = i;
|
|
list.push_back(quoteID);
|
|
type = true;
|
|
}
|
|
if (ss.peek() == ',' || ss.peek() == ' ') {
|
|
ss.ignore();
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
} // namespace Quotes
|