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:
@ -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__*/
|
||||
|
||||
Reference in New Issue
Block a user