Skip to content

Commit

Permalink
Add trivial data TU.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Oct 11, 2024
1 parent 98259dd commit 5c2f4b8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/serialization/source/common/TrivialData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "logging/String.h"

#include "serialization/TrivialData.h"

#include <string>
#include <vector>
#include <sstream>

namespace l::serialization {

std::vector<std::string> ParseTrivialData(std::stringstream& data, std::string_view separators) {

std::vector<std::string> out;

for (std::string line; std::getline(data, line, '\n');) {
auto elements = l::string::split(line, separators);
for (auto it : elements) {
out.push_back(std::string(it));
}
}

return out;
}

std::unordered_map<uint32_t, std::string> ParseTrivialDataMap(std::stringstream& data, std::string_view separators) {

auto out = ParseTrivialData(data, separators);

std::unordered_map<uint32_t, std::string> map;

for (int i = 0; i < out.size() / 2; i++) {
uint32_t key = l::string::string_id(out[i * 2]);
map[key] = out[i * 2 + 1];
}

return map;
}

}

0 comments on commit 5c2f4b8

Please sign in to comment.