uri: use begin and end methods, not variables
This commit is contained in:
parent
49e60e576f
commit
e14b17c0bd
36
uri.cpp.rl
36
uri.cpp.rl
@ -32,20 +32,20 @@
|
||||
action success {__success = true; }
|
||||
action failure {__success = false; }
|
||||
|
||||
action scheme_begin { m_views[SCHEME].begin = p; }
|
||||
action scheme_end { m_views[SCHEME].end = p; }
|
||||
action scheme_begin { m_views[SCHEME] = { p, nullptr }; }
|
||||
action scheme_end { m_views[SCHEME] = { m_views[SCHEME].begin (), p }; }
|
||||
|
||||
action authority_begin { m_views[AUTHORITY].begin = p; }
|
||||
action authority_end { m_views[AUTHORITY].end = p; }
|
||||
action authority_begin { m_views[AUTHORITY] = { p, nullptr}; }
|
||||
action authority_end { m_views[AUTHORITY] = { m_views[AUTHORITY].begin (), p }; }
|
||||
|
||||
action path_begin { m_views[PATH].begin = p; }
|
||||
action path_end { m_views[PATH].end = p; }
|
||||
action path_begin { m_views[PATH] = { p, nullptr}; }
|
||||
action path_end { m_views[PATH] = { m_views[PATH].begin (), p }; }
|
||||
|
||||
action query_begin { m_views[QUERY].begin = p; }
|
||||
action query_end { m_views[QUERY].end = p; }
|
||||
action query_begin { m_views[QUERY] = { p, nullptr}; }
|
||||
action query_end { m_views[QUERY] = { m_views[QUERY].begin (), p }; }
|
||||
|
||||
action fragment_begin { m_views[FRAGMENT].begin = p; }
|
||||
action fragment_end { m_views[FRAGMENT].end = p; }
|
||||
action fragment_begin { m_views[FRAGMENT] = { p, nullptr}; }
|
||||
action fragment_end { m_views[FRAGMENT] = { m_views[FRAGMENT].begin (), p }; }
|
||||
|
||||
## Characters
|
||||
unreserved = alpha | digit | "-" | "." | "_" | "~";
|
||||
@ -224,11 +224,11 @@ util::uri::percent_decode (view s)
|
||||
|
||||
// Early check for late percent-encoding so we can simplify the decode loop
|
||||
{
|
||||
auto tail = std::find (s.size () < 3 ? s.begin
|
||||
: s.end - 2,
|
||||
s.end,
|
||||
auto tail = std::find (s.size () < 3 ? s.begin ()
|
||||
: s.end () - 2,
|
||||
s.end (),
|
||||
'%');
|
||||
if (tail != s.end)
|
||||
if (tail != s.end ())
|
||||
throw parse_error ("triple overlaps end");
|
||||
}
|
||||
|
||||
@ -240,11 +240,11 @@ util::uri::percent_decode (view s)
|
||||
// Find the percent, copy until that, decode, advance, repeat.
|
||||
auto out_cursor = out.begin ();
|
||||
|
||||
for (auto i = s.begin; i < s.end; ++i) {
|
||||
auto cursor = std::find (i, s.end, '%');
|
||||
for (auto i = s.begin (); i < s.end (); ++i) {
|
||||
auto cursor = std::find (i, s.end (), '%');
|
||||
|
||||
if (cursor == s.end) {
|
||||
out_cursor = std::copy (i, s.end, out_cursor);
|
||||
if (cursor == s.end ()) {
|
||||
out_cursor = std::copy (i, s.end (), out_cursor);
|
||||
break;
|
||||
}
|
||||
|
||||
|
46
view.cpp
46
view.cpp
@ -27,25 +27,49 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
util::view::view ():
|
||||
begin (nullptr),
|
||||
end (nullptr)
|
||||
m_begin (nullptr),
|
||||
m_end (nullptr)
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
util::view::view (const char *str):
|
||||
begin (str),
|
||||
end (str + strlen (str))
|
||||
m_begin (str),
|
||||
m_end (str + strlen (str))
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
util::view::view (const char *_begin,
|
||||
const char *_end):
|
||||
m_begin (_begin),
|
||||
m_end (_end)
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
const char*
|
||||
util::view::begin (void) const
|
||||
{
|
||||
return m_begin;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
const char*
|
||||
util::view::end (void) const
|
||||
{
|
||||
return m_end;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool
|
||||
util::view::view::empty (void) const
|
||||
{
|
||||
return begin == nullptr ||
|
||||
end == nullptr ||
|
||||
begin == end;
|
||||
return m_begin == nullptr ||
|
||||
m_end == nullptr ||
|
||||
m_begin == m_end;
|
||||
}
|
||||
|
||||
|
||||
@ -53,7 +77,7 @@ util::view::view::empty (void) const
|
||||
size_t
|
||||
util::view::size (void) const
|
||||
{
|
||||
return end - begin;
|
||||
return m_end - m_begin;
|
||||
}
|
||||
|
||||
|
||||
@ -61,8 +85,8 @@ util::view::size (void) const
|
||||
const char&
|
||||
util::view::operator[] (size_t idx) const
|
||||
{
|
||||
CHECK_LT (begin + idx, end);
|
||||
return begin[idx];
|
||||
CHECK_LT (m_begin + idx, m_end);
|
||||
return m_begin[idx];
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +94,7 @@ util::view::operator[] (size_t idx) const
|
||||
std::ostream&
|
||||
util::operator<< (std::ostream &os, util::view s)
|
||||
{
|
||||
std::copy (s.begin, s.end, std::ostream_iterator<char> (os));
|
||||
std::copy (s.begin (), s.end (), std::ostream_iterator<char> (os));
|
||||
return os;
|
||||
}
|
||||
|
||||
|
15
view.hpp
15
view.hpp
@ -25,18 +25,25 @@
|
||||
#include <iostream>
|
||||
|
||||
namespace util {
|
||||
struct view {
|
||||
class view {
|
||||
public:
|
||||
view ();
|
||||
view (const char*);
|
||||
view (const char *str);
|
||||
view (const char *first, const char *last);
|
||||
|
||||
const char *begin;
|
||||
const char *end;
|
||||
const char *begin (void) const;
|
||||
const char *end (void) const;
|
||||
|
||||
bool empty () const;
|
||||
size_t size (void) const;
|
||||
const char& operator[] (size_t) const;
|
||||
|
||||
private:
|
||||
const char *m_begin;
|
||||
const char *m_end;
|
||||
};
|
||||
|
||||
|
||||
std::ostream& operator<< (std::ostream&, view);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user