Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-xmltooling.git] / xmltooling / util / URLEncoder.h
1 /*
2  *  Copyright 2001-2009 Internet2
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/util/URLEncoder.h
19  *
20  * Interface to a URL-encoding mechanism along with a default implementation.
21  */
22
23 #ifndef __xmltool_urlenc_h__
24 #define __xmltool_urlenc_h__
25
26 #include <xmltooling/base.h>
27
28 namespace xmltooling {
29     /**
30      * Interface to a URL-encoding mechanism along with a default implementation.
31      *
32      * Since URL-encoding is not canonical, it's important that the same
33      * encoder is used during some library operations and the calling code.
34      * Applications can supply an alternative implementation to the library
35      * if required.
36      */
37     class XMLTOOL_API URLEncoder {
38         MAKE_NONCOPYABLE(URLEncoder);
39     public:
40         /** Default constructor. */
41         URLEncoder() {}
42
43         virtual ~URLEncoder() {}
44
45         /**
46          * Produce a URL-safe but equivalent version of the input string.
47          *
48          * @param s input string to encode
49          * @return a string object containing the result of encoding the input
50          */
51         virtual std::string encode(const char* s) const;
52
53         /**
54          * Perform an in-place decoding operation on the input string.
55          * The resulting string will be NULL-terminated.
56          *
57          * @param s input string to decode in a writable buffer
58          */
59         virtual void decode(char* s) const;
60
61     protected:
62         /**
63          * Returns true iff the input character requires encoding.
64          *
65          * @param ch    the character to check
66          * @return  true iff the character should be encoded
67          */
68         virtual bool isBad(char ch) const;
69     };
70 };
71
72 #endif /* __xmltool_urlenc_h__ */