mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
feat: conversion toml::string <-> string_view
This commit is contained in:
@@ -4,6 +4,11 @@
|
|||||||
#define TOML11_STRING_HPP
|
#define TOML11_STRING_HPP
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#if __has_include(<string_view>)
|
||||||
|
#include <string_view>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace toml
|
namespace toml
|
||||||
{
|
{
|
||||||
@@ -40,6 +45,17 @@ struct string
|
|||||||
operator std::string const& () const& noexcept {return str;}
|
operator std::string const& () const& noexcept {return str;}
|
||||||
operator std::string&& () && noexcept {return std::move(str);}
|
operator std::string&& () && noexcept {return std::move(str);}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
explicit string(std::string_view s): kind(string_t::basic), str(s){}
|
||||||
|
string(std::string_view s, string_t k): kind(k), str(s){}
|
||||||
|
|
||||||
|
string& operator=(std::string_view s)
|
||||||
|
{kind = string_t::basic; str = s; return *this;}
|
||||||
|
|
||||||
|
explicit operator std::string_view() const noexcept
|
||||||
|
{return std::string_view(str);}
|
||||||
|
#endif
|
||||||
|
|
||||||
string_t kind;
|
string_t kind;
|
||||||
std::string str;
|
std::string str;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user