fragment.h
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 #ifndef __TERRALIB_COMMON_INTERNAL_FRAGMENT_H
23 #define __TERRALIB_COMMON_INTERNAL_FRAGMENT_H
24 #include "../Config.h"
25 #include <string>
26 #include <iostream>
27 namespace te
28 {
29  namespace common
30  {
31  namespace uri
32  {
33  /** \brief URI fragment component.
34  *
35  * Syntax (see uri_path for additional definitions): String
36  * is pct-decoded after parsing.
37  * <pre>
38  * fragment = *( pchar | "/" | "?" )
39  * </pre>
40  * @see http://tools.ietf.org/html/rfc3986#section-3.5 */
42  public:
43  fragment(); ///< Construct.
44  /// Construct from encoded string.
45  /// Note that this should not contain the leading '#'.
46  /// See \c parse() for less strict construction.
47  /// @exception std::invalid_argument if invalid encoding
48  fragment(const std::string& v);
49  bool empty() const {return is_null();} ///< Test if null/empty.
50  bool is_null() const {return string_.empty();} ///< Test if null/empty.
51  const std::string& string() const {return string_;} ///< Get decoded string.
52  std::string encoding() const; ///< Calculate encoded string.
53  private:
54  friend bool TECOMMONEXPORT parse(std::string::const_iterator& first, std::string::const_iterator last, fragment& v, std::string* errs);
55  std::string string_;
56  };
57  /// Parse URI fragment, returning whether found or not
58  /// and advancing first and setting fragment if found.
59  /// Does not skip leading space.
60  ///
61  /// If \p errs is specified the following take place:<ul>
62  /// <li>Errors in decoding the string do not
63  /// cause an immediate false return and and error message
64  /// is reported in the error string \p errs. The string
65  /// is used without decoding (i.e. assumes an unencoded '%').</li>
66  /// </ul>
67  bool TECOMMONEXPORT parse(std::string::const_iterator& first, std::string::const_iterator last, fragment& v, std::string* errs = 0);
68  /// Stream out fragment encoding.
69  inline std::ostream& operator <<(std::ostream& os, const fragment& v) {return os << v.encoding();}
70  }
71  }
72 }
73 #endif
bool empty() const
Test if null/empty.
Definition: fragment.h:49
std::ostream & operator<<(std::ostream &os, const authority &v)
Stream out URI authority.
Definition: authority.h:95
bool TECOMMONEXPORT 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...
URI fragment component.
Definition: fragment.h:41
URI C++ Library.
const std::string & string() const
Get decoded string.
Definition: fragment.h:51
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
std::string encoding() const
Calculate encoded string.
bool is_null() const
Test if null/empty.
Definition: fragment.h:50