urisyn.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_URISYN_H
23 #define __TERRALIB_COMMON_INTERNAL_URISYN_H
24 #include "../Config.h"
25 #include "utils.h"
26 #include <string>
27 namespace te
28 {
29  namespace common
30  {
31  namespace uri
32  {
33  /// URI syntax declarations.
34  namespace urisyn {
35  /// Char class.
36  enum char_class_e {
37  CINV = -2, ///< invalid
38  CEND = -1, ///< end delimitor
39  CVAL = 0, ///< valid any position
40  CVA2 = 1 ///< valid anywhere but 1st position
41  };
42  /// Traits used for parsing and encoding components.
44  const char* begin_cstring; ///< begin cstring (or 0 if none)
45  const char begin_char; ///< begin char (or 0 if none)
46  const char end_char; ///< end char (or 0 if none)
47  char char_class[256]; ///< map of char to class
48  };
49  /// Parse the URI componet, returning whether successful and setting
50  /// the string and end char and advancing if so.
51  /// This looks for end chars either returning the string up to, but not
52  /// including, the end char or returning the string up to the first
53  /// character that is not valid for the component.
54  /// The arg \p first is advanced after the end char if there is one.
55  /// The arg \p endc is set to either 0 if no end char found or to
56  /// the end char. If the first char is an end char then
57  /// true is returned and the string will be empty.
58  /// Leading white space is not skipped.
59  ///
60  /// The component is not decoded and should not be decoded until
61  /// after futher parsing with the component's subdelimiters, if any.
62  bool TECOMMONEXPORT parse(const traits& ts, std::string::const_iterator& first, std::string::const_iterator last, std::string& comp, char* endc = 0);
63  /// Encode the URI (sub) component. Note that this should be used on the
64  /// subcomponents before appending to subdelimiter chars, if any.
65  ///
66  /// From the RFC: URI producing applications should percent-encode data octets
67  /// that correspond to characters in the reserved set unless these characters
68  /// are specifically allowed by the URI scheme to represent data in that
69  /// component. If a reserved character is found in a URI component and
70  /// no delimiting role is known for that character, then it must be
71  /// interpreted as representing the data octet corresponding to that
72  /// character's encoding in US-ASCII.
73  /// @see http://tools.ietf.org/html/rfc3986
74  /// @see decode
75  std::string TECOMMONEXPORT encode(const traits& ts, const std::string& comp); // Modified by Lauro
76  /// Decode the pct-encoded (hex) sequences, if any, return success.
77  /// Does not change string on error.
78  /// @see http://tools.ietf.org/html/rfc3986#section-2.1
79  /// @see encode
80  bool TECOMMONEXPORT decode(std::string& s); // Modified by Lauro
81  void TECOMMONEXPORT convertPlus2Space(std::string& s); // Added by Lauro
82  extern const char TECOMMONEXPORT ENCODE_BEGIN_CHAR; ///< encode begin char ('\%')
83  extern const traits TECOMMONEXPORT SCHEME_TRAITS; ///< scheme traits
84  extern const traits TECOMMONEXPORT AUTHORITY_TRAITS; ///< authority traits
85  extern const traits TECOMMONEXPORT PATH_TRAITS; ///< path traits
86  extern const traits TECOMMONEXPORT QUERY_TRAITS; ///< query traits
87  extern const traits TECOMMONEXPORT FRAGMENT_TRAITS; ///< fragment traits
88  }
89  }
90  }
91 }
92 #endif
const char * begin_cstring
begin cstring (or 0 if none)
Definition: urisyn.h:44
const traits TECOMMONEXPORT AUTHORITY_TRAITS
authority traits
const char end_char
end char (or 0 if none)
Definition: urisyn.h:46
const char TECOMMONEXPORT ENCODE_BEGIN_CHAR
encode begin char ('%')
void TECOMMONEXPORT convertPlus2Space(std::string &s)
bool TECOMMONEXPORT parse(const traits &ts, std::string::const_iterator &first, std::string::const_iterator last, std::string &comp, char *endc=0)
Parse the URI componet, returning whether successful and setting the string and end char and advancin...
std::string TECOMMONEXPORT encode(const traits &ts, const std::string &comp)
Encode the URI (sub) component.
URI C++ Library.
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
const traits TECOMMONEXPORT QUERY_TRAITS
query traits
const traits TECOMMONEXPORT PATH_TRAITS
path traits
bool TECOMMONEXPORT decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
Traits used for parsing and encoding components.
Definition: urisyn.h:43
char_class_e
Char class.
Definition: urisyn.h:36
const traits TECOMMONEXPORT SCHEME_TRAITS
scheme traits
valid any position
Definition: urisyn.h:39
const char begin_char
begin char (or 0 if none)
Definition: urisyn.h:45
const traits TECOMMONEXPORT FRAGMENT_TRAITS
fragment traits
valid anywhere but 1st position
Definition: urisyn.h:40