Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
optstr.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef INKSCAPE_UTIL_OPTSTR_H
3#define INKSCAPE_UTIL_OPTSTR_H
4/*
5 * Author: PBS <pbs3141@gmail.com>
6 * Copyright (C) 2022 Authors
7 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
8 */
9
10#include <string>
11#include <optional>
12
13namespace Inkscape {
14namespace Util {
15
16inline bool equal(std::optional<std::string> const &a, char const *b)
17{
18 return a && b ? *a == b : !a && !b;
19}
20
21inline auto to_opt(char const *s)
22{
23 return s ? std::make_optional<std::string>(s) : std::nullopt;
24}
25
26inline auto to_cstr(std::optional<std::string> const &s)
27{
28 return s ? s->c_str() : nullptr;
29}
30
31inline bool assign(std::optional<std::string> &a, char const *b)
32{
33 if (equal(a, b)) return false;
34 a = to_opt(b);
35 return true;
36}
37
38} // namespace Util
39} // namespace Inkscape
40
41#endif // INKSCAPE_UTIL_OPTSTR_H
Miscellaneous supporting code.
Definition document.h:93
bool equal(std::optional< std::string > const &a, char const *b)
Definition optstr.h:16
auto to_opt(char const *s)
Definition optstr.h:21
auto to_cstr(std::optional< std::string > const &s)
Definition optstr.h:26
bool assign(std::optional< std::string > &a, char const *b)
Definition optstr.h:31
Helper class to stream background task notifications as a series of messages.