1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
/* First checked in on 98/12/03 by John R. McMullen, derived from net.h/mkparse.c. */
48
/* valid mask values for NET_Escape() and NET_EscapedSize(). */
50
url_XAlphas = PR_BIT(0)
51
, url_XPAlphas = PR_BIT(1)
52
, url_Path = PR_BIT(2)
58
NS_COM char * nsEscape(const char * str, nsEscapeMask mask);
59
/* Caller must use nsCRT::free() on the result */
61
NS_COM char * nsUnescape(char * str);
62
/* decode % escaped hex codes into character values,
63
* modifies the parameter, returns the same buffer
66
NS_COM PRInt32 nsUnescapeCount (char * str);
67
/* decode % escaped hex codes into character values,
68
* modifies the parameter buffer, returns the length of the result
69
* (result may contain \0's).
73
nsEscapeHTML(const char * string);
76
nsEscapeHTML2(const PRUnichar *aSourceBuffer,
77
PRInt32 aSourceBufferLen = -1);
79
* Escape problem char's for HTML display
89
* NS_EscapeURL/NS_UnescapeURL constants for |flags| parameter:
92
/** url components **/
93
esc_Scheme = PR_BIT(0),
94
esc_Username = PR_BIT(1),
95
esc_Password = PR_BIT(2),
97
esc_Directory = PR_BIT(4),
98
esc_FileBaseName = PR_BIT(5),
99
esc_FileExtension = PR_BIT(6),
100
esc_FilePath = esc_Directory | esc_FileBaseName | esc_FileExtension,
101
esc_Param = PR_BIT(7),
102
esc_Query = PR_BIT(8),
104
/** special flags **/
105
esc_Minimal = esc_Scheme | esc_Username | esc_Password | esc_Host | esc_FilePath | esc_Param | esc_Query | esc_Ref,
106
esc_Forced = PR_BIT(10), /* forces escaping of existing escape sequences */
107
esc_OnlyASCII = PR_BIT(11), /* causes non-ascii octets to be skipped */
108
esc_OnlyNonASCII = PR_BIT(12), /* causes _graphic_ ascii octets (0x20-0x7E)
109
* to be skipped when escaping. causes all
110
* ascii octets to be skipped when unescaping */
111
esc_AlwaysCopy = PR_BIT(13), /* copy input to result buf even if escaping is unnecessary */
112
esc_Colon = PR_BIT(14), /* forces escape of colon */
113
esc_SkipControl = PR_BIT(15) /* skips C0 and DEL from unescaping */
119
* Escapes invalid char's in an URL segment. Has no side-effect if the URL
120
* segment is already escaped. Otherwise, the escaped URL segment is appended
123
* @param str url segment string
124
* @param len url segment string length (-1 if unknown)
125
* @param flags url segment type flag
126
* @param result result buffer, untouched if part is already escaped
128
* @return TRUE if escaping was performed, FALSE otherwise.
130
NS_COM PRBool NS_EscapeURL(const char *str,
136
* Expands URL escape sequences... beware embedded null bytes!
138
* @param str url string to unescape
139
* @param len length of |str|
140
* @param flags only esc_OnlyNonASCII, esc_SkipControl and esc_AlwaysCopy
142
* @param result result buffer, untouched if |str| is already unescaped
144
* @return TRUE if unescaping was performed, FALSE otherwise.
146
NS_COM PRBool NS_UnescapeURL(const char *str,
151
/** returns resultant string length **/
152
inline PRInt32 NS_UnescapeURL(char *str) { return nsUnescapeCount(str); }
155
* string friendly versions...
157
inline const nsACString &
158
NS_EscapeURL(const nsASingleFragmentCString &part, PRInt16 partType, nsACString &result) {
160
if (NS_EscapeURL(part.BeginReading(temp), part.Length(), partType, result))
164
inline const nsACString &
165
NS_UnescapeURL(const nsASingleFragmentCString &str, PRInt16 flags, nsACString &result) {
167
if (NS_UnescapeURL(str.BeginReading(temp), str.Length(), flags, result))
172
inline nsAFlatCString &
173
NS_UnescapeURL(nsAFlatCString &str)
175
str.SetLength(nsUnescapeCount(str.BeginWriting()));