1ba61b67747e5ccc5fc39d272fadd43d1e14692b
[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         URLEncoder();
41
42         virtual ~URLEncoder();
43
44         /**
45          * Produce a URL-safe but equivalent version of the input string.
46          *
47          * @param s input string to encode
48          * @return a string object containing the result of encoding the input
49          */
50         virtual std::string encode(const char* s) const;
51
52         /**
53          * Perform an in-place decoding operation on the input string.
54          * The resulting string will be NULL-terminated.
55          *
56          * @param s input string to decode in a writable buffer
57          */
58         virtual void decode(char* s) const;
59
60     protected:
61         /**
62          * Returns true iff the input character requires encoding.
63          *
64          * @param ch    the character to check
65          * @return  true iff the character should be encoded
66          */
67         virtual bool isBad(char ch) const;
68     };
69 };
70
71 #endif /* __xmltool_urlenc_h__ */