0N/A/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 5556N/A/* ***** BEGIN LICENSE BLOCK ***** 0N/A * Version: MPL 1.1/GPL 2.0/LGPL 2.1 0N/A * The contents of this file are subject to the Mozilla Public License Version 0N/A * 1.1 (the "License"); you may not use this file except in compliance with 2362N/A * the License. You may obtain a copy of the License at 0N/A * Software distributed under the License is distributed on an "AS IS" basis, 0N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 0N/A * for the specific language governing rights and limitations under the 0N/A * The Original Code is mozilla.org code. 0N/A * The Initial Developer of the Original Code is 0N/A * Netscape Communications Corporation. 0N/A * Portions created by the Initial Developer are Copyright (C) 1998 0N/A * the Initial Developer. All Rights Reserved. 0N/A * Alternatively, the contents of this file may be used under the terms of 0N/A * either of the GNU General Public License Version 2 or later (the "GPL"), 0N/A * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 0N/A * in which case the provisions of the GPL or the LGPL are applicable instead 0N/A * of those above. If you wish to allow use of your version of this file only 0N/A * under the terms of either the GPL or the LGPL, and not to allow others to 0N/A * use your version of this file under the terms of the MPL, indicate your 0N/A * decision by deleting the provisions above and replace them with the notice 0N/A * and other provisions required by the GPL or the LGPL. If you do not delete 5556N/A * the provisions above, a recipient may use your version of this file under 5556N/A * the terms of any one of the MPL, the GPL or the LGPL. 0N/A * ***** END LICENSE BLOCK ***** */ 0N/A/* Bit 0 xalpha -- the alphas 0N/A** Bit 1 xpalpha -- as xalpha but 0N/A** converts spaces to plus and plus to %2B 0N/A** Bit 3 ... path -- as xalphas but doesn't escape '/' 0N/A /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 0N/A { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 0x */ 0N/A 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 1x */ 0N/A 0,0,0,0,0,0,0,0,0,0,
7,
4,0,
7,
7,
4,
/* 2x !"#$%&'()*+,-./ */ 0N/A 7,
7,
7,
7,
7,
7,
7,
7,
7,
7,0,0,0,0,0,0,
/* 3x 0123456789:;<=>? */ 0N/A 0,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
/* 4x @ABCDEFGHIJKLMNO */ 0N/A /* bits for '@' changed from 7 to 0 so '@' can be escaped */ 0N/A /* in usernames and passwords in publishing. */ 0N/A 7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,0,0,0,0,
7,
/* 5X PQRSTUVWXYZ[\]^_ */ 0N/A 0,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
/* 6x `abcdefghijklmno */ 0N/A 7,
7,
7,
7,
7,
7,
7,
7,
7,
7,
7,0,0,0,0,0,
/* 7X pqrstuvwxyz{\}~ DEL */ 0N/A/* decode % escaped hex codes into character values 0N/A ((C >=
'0' && C <=
'9') ? C -
'0' : \
0N/A ((C >=
'A' && C <=
'F') ? C -
'A' +
10 : \
0N/A ((C >=
'a' && C <=
'f') ? C -
'a' +
10 : 0)))
0N/A//---------------------------------------------------------------------------------------- 0N/A//---------------------------------------------------------------------------------------- 0N/A register const unsigned char*
src = (
const unsigned char *)
str;
0N/A extra +=
2;
/* the escape, plus an extra byte for each nibble */ 5556N/A *
dst++ =
'+';
/* convert spaces to pluses */ 0N/A *
dst =
'\0';
/* tack on eos */ 0N/A//---------------------------------------------------------------------------------------- 0N/A//---------------------------------------------------------------------------------------- 0N/A//---------------------------------------------------------------------------------------- 0N/A//---------------------------------------------------------------------------------------- 4566N/A//---------------------------------------------------------------------------------------- 4566N/A//---------------------------------------------------------------------------------------- 0N/A static const char hexChars[] =
"0123456789ABCDEFabcdef";
0N/A /* XXX Hardcoded max entity len. The +1 is for the trailing null. */ 0N/A // if the caller didn't calculate the length 0N/A /* XXX Hardcoded max entity len. */ 0N/A//---------------------------------------------------------------------------------------- 0N/A/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 0N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x */ 0N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 1x */ 0N/A 0,
1023, 0,
512,
1023, 0,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
953,
784,
/* 2x !"#$%&'()*+,-./ */ 0N/A 1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1008,
912, 0,
1008, 0,
768,
/* 3x 0123456789:;<=>? */ 0N/A 1008,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
/* 4x @ABCDEFGHIJKLMNO */ 0N/A 1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
896,
896,
896,
896,
1023,
/* 5x PQRSTUVWXYZ[\]^_ */ 0N/A 0,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
/* 6x `abcdefghijklmno */ 0N/A 1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
1023,
896,
1012,
896,
1023, 0,
/* 7x pqrstuvwxyz{|}~ */ 0N/A//---------------------------------------------------------------------------------------- 0N/A/* returns an escaped string */ 0N/A/* use the following masks to specify which 0N/A part of an URL you want to escape: 0N/A esc_FileBaseName = 32 0N/A esc_FileExtension = 64 0N/A/* by default this function will not escape parts of a string 0N/A that already look escaped, which means it already includes 0N/A a valid hexcode. This is done to avoid multiple escapes of 0N/A a string. Use the following mask to force escaping of a 0N/A register const unsigned char*
src = (
const unsigned char *)
part;
0N/A // if the char has not to be escaped or whatever follows % is 0N/A // a valid escaped string, just copy the char. 0N/A // Also the % will not be escaped until forced 0N/A // See bugzilla bug 61269 for details why we changed this 0N/A // And, we will not escape non-ascii characters if requested. 0N/A // On special request we will also escape the colon even when 0N/A // not covered by the matrix. 0N/A // ignoreAscii is not honored for control characters (C0 and DEL) 0N/A else /* do the escape magic */ 0N/A static const char hexChars[] =
"0123456789ABCDEFabcdef";
0N/A for (
int i=0; i<
len; ++i, ++p) {
0N/A //printf("%c [i=%d of len=%d]\n", *p, i, len); 0N/A unsigned char *
p1 = ((
unsigned char *) p) +
1;
0N/A unsigned char *
p2 = ((
unsigned char *) p) +
2;
0N/A (*
p1 <
'2' || (*
p1 ==
'7' && (*
p2 ==
'f' || *
p2 ==
'F'))))) {
0N/A //printf("- p1=%c p2=%c\n", *p1, *p2); 0N/A //printf("- p=%p, last=%p\n", p, last); 0N/A //printf("- u=%c\n", u);