option: rename to to_string_opt and to_string_view_opt

to_option_string -> to_string_opt
to_string_view   -> to_string_view_opt
This commit is contained in:
Dirk-Jan C. Binnema
2022-04-16 13:16:29 +03:00
parent 4f9c154d1a
commit 7c51bc68d4
9 changed files with 104 additions and 77 deletions

View File

@ -15,6 +15,7 @@
#define MU_OPTION__
#include "optional.hpp"
#include <string>
namespace Mu {
@ -29,5 +30,31 @@ Some(T&& t)
}
constexpr auto Nothing = tl::nullopt; // 'None' is take already
/**
* Maybe create a string from a const char pointer.
*
* @param str a char pointer or NULL
*
* @return option with either the string or nothing if str was NULL.
*/
Option<std::string>
static inline to_string_opt(const char* str) {
if (str)
return std::string{str};
else
return Nothing;
}
/**
* Like maybe_string that takes a const char*, but additionally,
* g_free() the string.
*
* @param str char pointer or NULL (consumed)
*
* @return option with either the string or nothing if str was NULL.
*/
Option<std::string> to_string_opt_gchar(char*&& str);
} // namespace Mu
#endif /*MU_OPTION__*/