mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-21 22:28:07 +08:00
feat: add u8string ctor
This commit is contained in:
@@ -48,7 +48,7 @@ template<typename TC>
|
|||||||
error_info make_type_error(const basic_value<TC>&, const std::string&, const value_t);
|
error_info make_type_error(const basic_value<TC>&, const std::string&, const value_t);
|
||||||
|
|
||||||
template<typename TC>
|
template<typename TC>
|
||||||
error_info make_not_found_error(const basic_value<TC>&, const std::string&, const std::string&);
|
error_info make_not_found_error(const basic_value<TC>&, const std::string&, const typename basic_value<TC>::key_type&);
|
||||||
|
|
||||||
template<typename TC>
|
template<typename TC>
|
||||||
void change_region_of_value(basic_value<TC>&, const basic_value<TC>&);
|
void change_region_of_value(basic_value<TC>&, const basic_value<TC>&);
|
||||||
@@ -76,6 +76,7 @@ class basic_value
|
|||||||
using array_type = typename config_type::template array_type<value_type>;
|
using array_type = typename config_type::template array_type<value_type>;
|
||||||
using table_type = typename config_type::template table_type<key_type, value_type>;
|
using table_type = typename config_type::template table_type<key_type, value_type>;
|
||||||
using comment_type = typename config_type::comment_type;
|
using comment_type = typename config_type::comment_type;
|
||||||
|
using char_type = typename string_type::value_type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -643,6 +644,66 @@ class basic_value
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // TOML11_HAS_STRING_VIEW
|
#endif // TOML11_HAS_STRING_VIEW
|
||||||
|
|
||||||
|
#if defined(TOML11_HAS_CHAR8_T)
|
||||||
|
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||||
|
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
|
||||||
|
std::is_same<cxx::remove_cvref_t<T>, std::u8string>
|
||||||
|
>::value, std::nullptr_t> = nullptr>
|
||||||
|
basic_value(const T& x)
|
||||||
|
: basic_value(x, string_format_info{}, std::vector<std::string>{}, region_type{})
|
||||||
|
{}
|
||||||
|
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||||
|
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
|
||||||
|
std::is_same<cxx::remove_cvref_t<T>, std::u8string>
|
||||||
|
>::value, std::nullptr_t> = nullptr>
|
||||||
|
basic_value(const T& x, string_format_info fmt)
|
||||||
|
: basic_value(x, std::move(fmt), std::vector<std::string>{}, region_type{})
|
||||||
|
{}
|
||||||
|
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||||
|
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
|
||||||
|
std::is_same<cxx::remove_cvref_t<T>, std::u8string>
|
||||||
|
>::value, std::nullptr_t> = nullptr>
|
||||||
|
basic_value(const T& x, std::vector<std::string> com)
|
||||||
|
: basic_value(x, string_format_info{}, std::move(com), region_type{})
|
||||||
|
{}
|
||||||
|
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||||
|
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
|
||||||
|
std::is_same<cxx::remove_cvref_t<T>, std::u8string>
|
||||||
|
>::value, std::nullptr_t> = nullptr>
|
||||||
|
basic_value(const T& x, string_format_info fmt, std::vector<std::string> com)
|
||||||
|
: basic_value(x, std::move(fmt), std::move(com), region_type{})
|
||||||
|
{}
|
||||||
|
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||||
|
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
|
||||||
|
std::is_same<cxx::remove_cvref_t<T>, std::u8string>
|
||||||
|
>::value, std::nullptr_t> = nullptr>
|
||||||
|
basic_value(const T& x, string_format_info fmt,
|
||||||
|
std::vector<std::string> com, region_type reg)
|
||||||
|
: type_(value_t::string),
|
||||||
|
string_(string_storage(detail::to_string_of<char_type>(x), std::move(fmt))),
|
||||||
|
region_(std::move(reg)), comments_(std::move(com))
|
||||||
|
{}
|
||||||
|
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||||
|
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
|
||||||
|
std::is_same<cxx::remove_cvref_t<T>, std::u8string>
|
||||||
|
>::value, std::nullptr_t> = nullptr>
|
||||||
|
basic_value& operator=(const T& x)
|
||||||
|
{
|
||||||
|
string_format_info fmt;
|
||||||
|
if(this->is_string())
|
||||||
|
{
|
||||||
|
fmt = this->as_string_fmt();
|
||||||
|
}
|
||||||
|
this->cleanup();
|
||||||
|
this->type_ = value_t::string;
|
||||||
|
this->region_ = region_type{};
|
||||||
|
assigner(this->string_, string_storage(detail::to_string_of<char_type>(x), std::move(fmt)));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TOML11_HAS_STRING_VIEW
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
// constructor (local_date) =========================================== {{{
|
// constructor (local_date) =========================================== {{{
|
||||||
@@ -2062,10 +2123,10 @@ error_info make_type_error(const basic_value<TC>& v, const std::string& fname, c
|
|||||||
v.location(), "the actual type is " + to_string(v.type()));
|
v.location(), "the actual type is " + to_string(v.type()));
|
||||||
}
|
}
|
||||||
template<typename TC>
|
template<typename TC>
|
||||||
error_info make_not_found_error(const basic_value<TC>& v, const std::string& fname, const std::string& key)
|
error_info make_not_found_error(const basic_value<TC>& v, const std::string& fname, const typename basic_value<TC>::key_type& key)
|
||||||
{
|
{
|
||||||
const auto loc = v.location();
|
const auto loc = v.location();
|
||||||
const std::string title = fname + ": key \"" + key + "\" not found";
|
const std::string title = fname + ": key \"" + to_string_of<char>(key) + "\" not found";
|
||||||
|
|
||||||
std::vector<std::pair<source_location, std::string>> locs;
|
std::vector<std::pair<source_location, std::string>> locs;
|
||||||
if( ! loc.is_ok())
|
if( ! loc.is_ok())
|
||||||
|
Reference in New Issue
Block a user