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.
20 * Interface to a URL-encoding mechanism along with a
21 * default implementation.
25 #include "util/URLEncoder.h"
27 using namespace xmltooling;
30 static char x2c(char *what)
34 digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
36 digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
40 void URLEncoder::decode(char* s) const
44 for(x=0,y=0;s[y];++x,++y)
46 if((s[x] = s[y]) == '%')
59 static inline char hexchar(unsigned short s)
61 return (s<=9) ? ('0' + s) : ('A' + s - 10);
64 string URLEncoder::encode(const char* s) const
70 ret+=hexchar((unsigned char)*s >> 4);
71 ret+=hexchar((unsigned char)*s & 0x0F);