mirror of
https://github.com/matrix-construct/construct
synced 2024-05-19 19:33:45 +02:00
ircd::lex: Handle js null as falsy boolean.
This commit is contained in:
parent
4c44125d37
commit
a9b22c9052
|
@ -219,14 +219,15 @@ ircd::lex_cast(bool i,
|
||||||
template<> bool
|
template<> bool
|
||||||
ircd::lex_cast(const string_view &s)
|
ircd::lex_cast(const string_view &s)
|
||||||
{
|
{
|
||||||
const bool literal[2]
|
const bool literal[]
|
||||||
{
|
{
|
||||||
s == "true",
|
s == "true",
|
||||||
s == "false",
|
s == "false",
|
||||||
|
s == "null",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle the common cases early in this frame before call.
|
// Handle the common cases early in this frame before call.
|
||||||
if(likely(literal[0] | literal[1]))
|
if(likely(literal[0] | literal[1] | literal[2]))
|
||||||
return literal[0];
|
return literal[0];
|
||||||
|
|
||||||
return lex::cast<bool, lex::to_bool>(s);
|
return lex::cast<bool, lex::to_bool>(s);
|
||||||
|
@ -236,14 +237,15 @@ template<> bool
|
||||||
ircd::lex_castable<bool>(const string_view &s)
|
ircd::lex_castable<bool>(const string_view &s)
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
const bool literal[2]
|
const bool literal[]
|
||||||
{
|
{
|
||||||
s == "true",
|
s == "true",
|
||||||
s == "false",
|
s == "false",
|
||||||
|
s == "null",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle the common cases early in this frame before call.
|
// Handle the common cases early in this frame before call.
|
||||||
if(likely(literal[0] | literal[1]))
|
if(likely(literal[0] | literal[1] | literal[2]))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return lex::test<bool, lex::is_bool>(s);
|
return lex::test<bool, lex::is_bool>(s);
|
||||||
|
|
Loading…
Reference in a new issue