2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file xmltooling/util/URLEncoder.h
20 * Interface to a URL-encoding mechanism along with a
21 * default implementation.
24 #ifndef __xmltool_urlenc_h__
25 #define __xmltool_urlenc_h__
27 #include <xmltooling/base.h>
29 namespace xmltooling {
31 * Interface to a URL-encoding mechanism along with a default implementation.
33 * Since URL-encoding is not canonical, it's important that the same
34 * encoder is used during some library operations and the calling code.
35 * Applications can supply an alternative implementation to the library
38 class XMLTOOL_API URLEncoder {
39 MAKE_NONCOPYABLE(URLEncoder);
42 virtual ~URLEncoder() {}
45 * Produce a URL-safe but equivalent version of the input string.
47 * @param s input string to encode
48 * @return a string object containing the result of encoding the input
50 virtual std::string encode(const char* s) const;
53 * Perform an in-place decoding operation on the input string.
54 * The resulting string will be NULL-terminated.
56 * @param s input string to decode in a writable buffer
58 virtual void decode(char* s) const;
62 * Returns true iff the input character requires encoding.
64 * @param ch the character to check
65 * @return true iff the character should be encoded
67 virtual bool isBad(char ch) const {
68 static char badchars[]="=&/?:\"\\+<>#%{}|^~[]`;@";
69 return (strchr(badchars,ch) || ch<=0x20 || ch>=0x7F);
74 #endif /* __xmltool_urlenc_h__ */