mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
ircd: Attempt to add these hacks to string_view.
This commit is contained in:
parent
dc1281a17c
commit
9e2910aa1f
1 changed files with 41 additions and 1 deletions
|
@ -35,6 +35,8 @@ namespace ircd
|
||||||
template<int (&test)(int) = std::isprint> auto ctype(const string_view &s);
|
template<int (&test)(int) = std::isprint> auto ctype(const string_view &s);
|
||||||
|
|
||||||
bool operator!(const string_view &);
|
bool operator!(const string_view &);
|
||||||
|
bool defined(const string_view &);
|
||||||
|
bool null(const string_view &);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Customized std::string_view (experimental TS / C++17)
|
/// Customized std::string_view (experimental TS / C++17)
|
||||||
|
@ -52,6 +54,30 @@ struct ircd::string_view
|
||||||
return !empty();
|
return !empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// (non-standard) When data() != nullptr we consider the string defined
|
||||||
|
/// downstream in this project wrt JS/JSON. This is the bit of information
|
||||||
|
/// we're deciding on for defined|undefined. If this string_view is
|
||||||
|
/// constructed from a literal "" we must assert that inputs a valid pointer
|
||||||
|
/// in the std::string_view with length 0; stdlib can't optimize that with
|
||||||
|
/// a nullptr replacement.
|
||||||
|
bool undefined() const
|
||||||
|
{
|
||||||
|
return data() == nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool defined() const
|
||||||
|
{
|
||||||
|
return !undefined();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// (non-standard) After using data() == nullptr for undefined, we're fresh
|
||||||
|
/// out of legitimate bits here to represent the null type string. In this
|
||||||
|
/// case we expect a hack pointer of 0x1 which will mean JS null
|
||||||
|
bool null() const
|
||||||
|
{
|
||||||
|
return data() == reinterpret_cast<const char *>(0x1);
|
||||||
|
}
|
||||||
|
|
||||||
// (non-standard) our faux insert stub
|
// (non-standard) our faux insert stub
|
||||||
// Tricks boost::spirit into thinking this is mutable string (hint: it's not).
|
// Tricks boost::spirit into thinking this is mutable string (hint: it's not).
|
||||||
// Instead, the raw[] directive in Qi grammar will use the iterator constructor only.
|
// Instead, the raw[] directive in Qi grammar will use the iterator constructor only.
|
||||||
|
@ -130,8 +156,10 @@ struct ircd::string_view
|
||||||
:std::string_view{bsv}
|
:std::string_view{bsv}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/// Our default constructor sets the elements to 0 for best behavior by
|
||||||
|
/// defined() and null() et al.
|
||||||
string_view()
|
string_view()
|
||||||
:std::string_view{}
|
:std::string_view{nullptr, 0}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
using std::string_view::string_view;
|
using std::string_view::string_view;
|
||||||
|
@ -271,6 +299,18 @@ ircd::operator!(const string_view &str)
|
||||||
return str.empty();
|
return str.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::null(const string_view &str)
|
||||||
|
{
|
||||||
|
return str.null();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::defined(const string_view &str)
|
||||||
|
{
|
||||||
|
return str.defined();
|
||||||
|
}
|
||||||
|
|
||||||
template<int (&test)(int)>
|
template<int (&test)(int)>
|
||||||
auto
|
auto
|
||||||
ircd::ctype(const string_view &s)
|
ircd::ctype(const string_view &s)
|
||||||
|
|
Loading…
Reference in a new issue