/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2015 Danny Robson */ #include "uri.hpp" #include #include // We generate some really old style C code via ragel here, so we have to // disable some noisy warnings (doubly so given -Werror) #pragma GCC diagnostic ignored "-Wold-style-cast" using cruft::uri; /////////////////////////////////////////////////////////////////////////////// %%{ machine impl; action trace { if (0) std::cerr << *p; } action success {__success = true; } action failure {__success = false; } action scheme_begin { m_views[SCHEME] = { p, p }; } action scheme_end { m_views[SCHEME] = { m_views[SCHEME].begin (), p }; } action hier_begin { m_views[HIERARCHICAL] = { p, p }; } action hier_end { m_views[HIERARCHICAL] = { m_views[HIERARCHICAL].begin (), p }; } action user_begin { m_views[USER] = { p, p }; } action user_end { m_views[USER] = { m_views[USER].begin (), p }; } action host_begin { m_views[HOST] = { p, p }; } action host_end { m_views[HOST] = { m_views[HOST].begin (), p }; } action port_begin { m_views[PORT] = { p, p }; } action port_end { m_views[PORT] = { m_views[PORT].begin (), p }; } action authority_begin { m_views[AUTHORITY] = { p, p}; } action authority_end { m_views[AUTHORITY] = { m_views[AUTHORITY].begin (), p }; } action path_begin { m_views[PATH] = { p, p}; } action path_end { m_views[PATH] = { m_views[PATH].begin (), p }; } action query_begin { m_views[QUERY] = { p, p}; } action query_end { m_views[QUERY] = { m_views[QUERY].begin (), p }; } action fragment_begin { m_views[FRAGMENT] = { p, p}; } action fragment_end { m_views[FRAGMENT] = { m_views[FRAGMENT].begin (), p }; } action uri_begin {} action uri_end {} include rfc3986 'rfc3986.rl'; impl := URI >uri_begin %uri_end %success $!failure $trace; write data; }%% /////////////////////////////////////////////////////////////////////////////// cruft::uri::uri (std::string &&_value): m_views { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }, m_value (std::move (_value)) { const char *p = m_value.data (); const char *pe = m_value.data () + m_value.size (); const char *eof = pe; bool __success = false; int cs; %%write init; %%write exec; if (!__success) throw parse_error ("invalid uri"); }