~aleteoryx/muditaos

ref: 7cdfb96db22bc1d7801cf95e98c349611ea300d0 muditaos/module-services/service-db/agents/quotes/QuotesSettingsSerializer.cpp -rw-r--r-- 890 bytes
7cdfb96d — Bartosz Cichocki [EGD-6823] Add quote randomization 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "QuotesSettingsSerializer.hpp"
#include <log/log.hpp>
#include <module-utils/utility/Utils.hpp>

namespace Quotes
{

    auto QuotesSettingsSerializer::serialize(const IdList &list) -> std::string
    {
        std::string output;
        for (const auto &item : list) {
            output.append(utils::to_string(item) + ',');
        }
        return output;
    }
    auto QuotesSettingsSerializer::deserialize(const std::string &listString) -> IdList
    {
        std::stringstream ss(listString);
        IdList list;
        for (int i; ss >> i;) {
            list.push_back(i);
            if (ss.peek() == ',' || ss.peek() == ' ') {
                ss.ignore();
            }
        }
        return list;
    }
} // namespace Quotes