From c853ffb5b2f75f5a889ed2e3ef89b818a736e87a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:50:49 +0200 Subject: Adding upstream version 1.3+ds. Signed-off-by: Daniel Baumann --- src/util/optstr.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/util/optstr.h (limited to 'src/util/optstr.h') 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 + * Copyright (C) 2022 Authors + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include + +namespace Inkscape { +namespace Util { + +inline bool equal(std::optional const &a, char const *b) +{ + return a && b ? *a == b : !a && !b; +} + +inline auto to_opt(char const *s) +{ + return s ? std::make_optional(s) : std::nullopt; +} + +inline auto to_cstr(std::optional const &s) +{ + return s ? s->c_str() : nullptr; +} + +inline bool assign(std::optional &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 -- cgit v1.2.3