From a9a5308cf03fcd25492317b844a59019eacfac13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 8 Apr 2023 18:35:46 +0200 Subject: Empty record item type --- src/storage.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/storage.cpp b/src/storage.cpp index 2e948b0..b5688bb 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1078,6 +1078,14 @@ RecordT::Item::operator bool() const return !holds_alternative(value); } +template +optional::Item::Empty> RecordT::Item::asEmpty() const +{ + if (holds_alternative::Item::Empty>(value)) + return std::get::Item::Empty>(value); + return nullopt; +} + template optional RecordT::Item::asInteger() const { @@ -1179,7 +1187,11 @@ optional> RecordT::decode(const S & st, begin = newline + 1; } - if (type == "i") + if (type == "e") { + if (value.size() != 0) + return nullopt; + items->emplace_back(name, typename Item::Empty {}); + } else if (type == "i") try { items->emplace_back(name, std::stoi(value)); } catch (invalid_argument &) { @@ -1271,7 +1283,10 @@ vector RecordT::encodeInner() const string type; string value; - if (auto x = item.asInteger()) { + if (item.asEmpty()) { + type = "e"; + value = ""; + } else if (auto x = item.asInteger()) { type = "i"; value = to_string(*x); } else if (auto x = item.asText()) { -- cgit v1.2.3