summaryrefslogtreecommitdiffstats
path: root/src/util/optstr.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
commitc853ffb5b2f75f5a889ed2e3ef89b818a736e87a (patch)
tree7d13a0883bb7936b84d6ecdd7bc332b41ed04bee /src/util/optstr.h
parentInitial commit. (diff)
downloadinkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.tar.xz
inkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.zip
Adding upstream version 1.3+ds.upstream/1.3+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/util/optstr.h')
-rw-r--r--src/util/optstr.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/util/optstr.h b/src/util/optstr.h
new file mode 100644
index 0000000..f8a0b4c
--- /dev/null
+++ b/src/util/optstr.h
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#ifndef INKSCAPE_UTIL_OPTSTR_H
+#define INKSCAPE_UTIL_OPTSTR_H
+/*
+ * Author: PBS <pbs3141@gmail.com>
+ * Copyright (C) 2022 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include <string>
+#include <optional>
+
+namespace Inkscape {
+namespace Util {
+
+inline bool equal(std::optional<std::string> const &a, char const *b)
+{
+ return a && b ? *a == b : !a && !b;
+}
+
+inline auto to_opt(char const *s)
+{
+ return s ? std::make_optional<std::string>(s) : std::nullopt;
+}
+
+inline auto to_cstr(std::optional<std::string> const &s)
+{
+ return s ? s->c_str() : nullptr;
+}
+
+inline bool assign(std::optional<std::string> &a, char const *b)
+{
+ if (equal(a, b)) return false;
+ a = to_opt(b);
+ return true;
+}
+
+} // namespace Util
+} // namespace Inkscape
+
+#endif // INKSCAPE_UTIL_OPTSTR_H