All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
scheme.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2009 zooml.com
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 #include "scheme.h"
23 #include "urisyn.h"
24 #include <stdexcept>
25 #include <boost/algorithm/string.hpp>
26 namespace te
27 {
28  namespace common
29  {
30  namespace uri
31  {
33  scheme::scheme(const std::string& v) {
34  std::string::const_iterator first = v.begin();
35  char endc;
36  if (!parse(first, v.end(), *this, &endc) || first != v.end() || endc)
37  throw std::invalid_argument("invalid URI scheme: \"" + v + "\"");
38  }
39  bool parse(std::string::const_iterator& first, std::string::const_iterator last, scheme& v, char* endc) {
40  //????? does endc need to be a ptr????
41  std::string tmp;
42  char ec;
43  //????? should "not empty" requirement be put in traits????
44  if (!urisyn::parse(urisyn::SCHEME_TRAITS, first, last, tmp, &ec) || tmp.empty())
45  return false;
46  boost::to_lower(tmp);
47  v.string_ = tmp;
48  if (endc)
49  *endc = ec;
50  return true;
51  }
52  }
53  }
54 }
friend bool TECOMMONEXPORT parse(std::string::const_iterator &first, std::string::const_iterator last, scheme &v, char *endc)
Parse URI scheme, returning whether found or not and advancing first and setting scheme and end char ...
Definition: scheme.cpp:39
bool parse(std::string::const_iterator &first, std::string::const_iterator last, authority &v)
Parse URI authority, returning whether found or not and advancing first and setting authority if foun...
Definition: authority.cpp:156
bool parse(const traits &ts, std::string::const_iterator &first, std::string::const_iterator last, std::string &comp, char *endc)
Parse the URI componet, returning whether successful and setting the string and end char and advancin...
Definition: urisyn.cpp:136
URI scheme component.
Definition: scheme.h:40
const traits SCHEME_TRAITS
scheme traits
Definition: urisyn.cpp:31
scheme()
Construct null.
Definition: scheme.cpp:32
std::string string_
Definition: scheme.h:54