5 #include "includes/desktopfileentry.h"
6 #include "includes/desktopfile_util.h"
8 namespace linuxdeploy {
9 namespace desktopfile {
10 class DesktopFileEntry::PrivateData {
16 void copyData(const std::shared_ptr<PrivateData>& other) {
21 void assertValueNotEmpty() {
23 throw std::invalid_argument("value is empty");
27 DesktopFileEntry::DesktopFileEntry() : d(new PrivateData) {}
29 DesktopFileEntry::DesktopFileEntry(std::string key, std::string value) : DesktopFileEntry() {
30 d->key = std::move(key);
31 d->value = std::move(value);
34 DesktopFileEntry::DesktopFileEntry(const DesktopFileEntry& other) : DesktopFileEntry() {
38 DesktopFileEntry& DesktopFileEntry::operator=(const DesktopFileEntry& other) {
40 d.reset(new PrivateData);
47 DesktopFileEntry& DesktopFileEntry::operator=(DesktopFileEntry&& other) noexcept {
56 bool DesktopFileEntry::operator==(const DesktopFileEntry& other) const {
57 return d->key == other.d->key && d->value == other.d->value;
60 bool DesktopFileEntry::operator!=(const DesktopFileEntry& other) const {
61 return !operator==(other);
64 bool DesktopFileEntry::isEmpty() const {
65 return d->key.empty();
68 const std::string& DesktopFileEntry::key() const {
72 const std::string& DesktopFileEntry::value() const {
76 int32_t DesktopFileEntry::asInt() const {
77 d->assertValueNotEmpty();
79 return lexicalCast<int32_t>(value());
82 int64_t DesktopFileEntry::asLong() const {
83 d->assertValueNotEmpty();
85 return lexicalCast<int64_t>(value());
88 double DesktopFileEntry::asDouble() const {
89 d->assertValueNotEmpty();
91 return lexicalCast<double>(value());
94 std::vector<std::string> DesktopFileEntry::parseStringList() const {
95 const auto& value = this->value();
100 // if (value.back() != ';')
101 // ldLog() << LD_DEBUG << "desktop file string list does not end with semicolon:" << value
104 std::vector<std::string> list;
106 std::stringstream ss(value);
108 std::string currentVal;
109 while (std::getline(ss, currentVal, ';')) {
110 // the last value will be empty, as in desktop files, lists shall end with a semicolon
111 // therefore we skip all empty values (assuming that empty values in lists in desktop files don't make sense anyway)
112 if (!currentVal.empty())
113 list.emplace_back(currentVal);