Skip to content

Commit

Permalink
[FOLD] charset work
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Nov 18, 2021
1 parent a3b6743 commit 48d14a9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 100 deletions.
59 changes: 0 additions & 59 deletions include/boost/http_proto/bnf/ctype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,65 +136,6 @@ struct iless_pred
using ws_set
= char_set_function<&is_ws>;

/** Character set for DIGIT
@par BNF
@code
DIGIT = %30-39
@endcode
*/
using digit_set
= char_set_function<&is_digit>;

/** Character set for HEXDIG
@par BNF
@code
HEXDIG = DIGIT / %x41-46 / %x61-66
@endcode
*/
class hexdig_set
{
char const* const tab_;

public:
BOOST_HTTP_PROTO_DECL
hexdig_set() noexcept;

bool
contains(
char c) const noexcept
{
auto const u = static_cast<
unsigned char>(c);
return tab_[u] != 0x20;
}

template<class Char>
Char*
skip(
Char* first,
char const* end) const noexcept
{
while(first != end)
{
if(! contains(*first))
break;
++first;
}
return first;
}

/** Return the numeric value of a hex digit.
*/
int
value(char c) const noexcept
{
return tab_[static_cast<
unsigned char>(c)];
}
};

/** Character set for tchar
@par BNF
Expand Down
23 changes: 0 additions & 23 deletions include/boost/http_proto/bnf/impl/ctype.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,6 @@ iless(

//------------------------------------------------

hexdig_set::
hexdig_set() noexcept
: tab_(
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x20\x20\x20\x20\x20\x20"
"\x20\x0a\x0b\x0c\x0d\x0e\x0f\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x0a\x0b\x0c\x0d\x0e\x0f\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
)
{
}

tchar_set::
tchar_set() noexcept
: char_set_table(
Expand Down
11 changes: 6 additions & 5 deletions include/boost/http_proto/bnf/impl/number.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <boost/http_proto/bnf/number.hpp>
#include <boost/http_proto/error.hpp>
#include <boost/http_proto/bnf/ctype.hpp>
#include <boost/url/bnf/charset.hpp>

namespace boost {
namespace http_proto {
Expand All @@ -30,15 +31,15 @@ parse(
ec = error::need_more;
return start;
}
digit_set ds;
auto ds = urls::bnf::digit_chars;
auto const max = (static_cast<
std::uint64_t>(-1));
auto const max10 = max / 10;
auto it = start;
v_ = 0;
do
{
if(! ds.contains(*it))
if(! ds(*it))
{
if(it == start)
{
Expand Down Expand Up @@ -81,15 +82,15 @@ parse(
ec = error::need_more;
return start;
}
hexdig_set hs;
auto const hs = urls::bnf::hexdig_chars;
auto const max = (static_cast<
std::uint64_t>(-1));
auto const max16 = max / 16;
auto it = start;
v_ = 0;
do
{
if(! hs.contains(*it))
if(! hs(*it))
{
if(it == start)
{
Expand All @@ -106,7 +107,7 @@ parse(
}
v_ *= 16;
std::uint64_t const d =
hs.value(*it);
urls::bnf::hexdig_value(*it);
if(max - v_ < d)
{
ec = error::numeric_overflow;
Expand Down
8 changes: 0 additions & 8 deletions test/bnf/ctype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ class ctype_test
check_set(ws_set(),
" \t");

check_set(digit_set(),
"0123456789");

check_set(hexdig_set(),
"0123456789"
"ABCDEF"
"abcdef");

check_set(tchar_set(),
"!#$%&'*+-.^_`|~"
"0123456789"
Expand Down
8 changes: 5 additions & 3 deletions test/bnf/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <boost/http_proto/bnf/algorithm.hpp>
#include <boost/http_proto/bnf/ctype.hpp>

#include <boost/url/bnf/charset.hpp>

#include "test_bnf.hpp"

namespace boost {
Expand Down Expand Up @@ -48,14 +50,14 @@ class list_test
ec = error::need_more;
return start;
}
digit_set ds;
auto const ds = urls::bnf::digit_chars;
auto it = start;
if(! ds.contains(*it))
if(! ds(*it))
{
ec = error::syntax;
return it;
}
it = ds.skip(it + 1, end);
it = ds.find_if_not(it + 1, end);
return it;
}
};
Expand Down
5 changes: 3 additions & 2 deletions test/bnf/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <boost/http_proto/string_view.hpp>
#include <boost/http_proto/bnf/algorithm.hpp>
#include <boost/http_proto/bnf/ctype.hpp>
#include <boost/url/bnf/charset.hpp>

#include "test_suite.hpp"

Expand Down Expand Up @@ -44,7 +45,7 @@ class sequence_test
char const* end,
error_code& ec)
{
digit_set ds;
auto const ds = urls::bnf::digit_chars;
auto it = start;
if(it == end)
{
Expand All @@ -57,7 +58,7 @@ class sequence_test
return start;
}
++it;
it = ds.skip(it, end);
it = ds.find_if_not(it, end);
if(it == start + 1)
{
// missing digits
Expand Down

0 comments on commit 48d14a9

Please sign in to comment.