version 1.94, 2003/08/25 15:15:02
|
version 1.95, 2003/08/26 20:46:28
|
|
|
} | } |
} | } |
| |
|
// chuck start |
|
|
// See http://www.ietf.org/rfc/rfc2396.txt section 2 | // See http://www.ietf.org/rfc/rfc2396.txt section 2 |
// Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ',' | // Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ',' |
// Excluded characters: | // Excluded characters: |
|
|
// Delimiters = '<' '>' '#' '%' '"' | // Delimiters = '<' '>' '#' '%' '"' |
// Unwise = '{' '}' '|' '\\' '^' '[' ']' '`' | // Unwise = '{' '}' '|' '\\' '^' '[' ']' '`' |
// | // |
// Also see the "CIM Operations over HTTP" spec, section 3.3.2 and |
|
// 3.3.3, for the treatment of non US-ASCII chars |
inline void _encodeURIChar(String& outString, Sint8 char8) |
inline void _encodeURIChar(String& outString, Char16 char16) |
|
{ |
|
// We need to convert the Char16 to UTF8 then append the UTF8 |
|
// character into the array. |
|
// NOTE: The UTF8 character could be several bytes long. |
|
// WARNING: This function will put in replacement character for |
|
// all characters that have surogate pairs. |
|
Uint8 str[6]; |
|
memset(str,0x00,sizeof(str)); |
|
Uint8* charIN = (Uint8 *)&char16; |
|
|
|
const Uint16 *strsrc = (Uint16 *)charIN; |
|
Uint16 *endsrc = (Uint16 *)&charIN[1]; |
|
|
|
Uint8 *strtgt = (Uint8 *)str; |
|
Uint8 *endtgt = (Uint8 *)&str[5]; |
|
|
|
UTF16toUTF8(&strsrc, |
|
endsrc, |
|
&strtgt, |
|
endtgt); |
|
|
|
// Loop through the UTF8 bytes for the character, |
|
// escaping as needed. |
|
Uint32 number1 = trailingBytesForUTF8[Uint32(str[0])]+1; |
|
for (Uint32 i = 0; i < number1; i++) |
|
{ | { |
Uint8 c = str[i]; |
Uint8 c = (Uint8)char8; |
| |
#ifndef PEGASUS_DO_NOT_IMPLEMENT_URI_ENCODING | #ifndef PEGASUS_DO_NOT_IMPLEMENT_URI_ENCODING |
if ( ((c <= 0x20) && (c >= 0x00)) || // Control characters + space char | if ( ((c <= 0x20) && (c >= 0x00)) || // Control characters + space char |
|
|
outString.append((Uint16)c); | outString.append((Uint16)c); |
} | } |
} | } |
} |
|
| |
String XmlWriter::encodeURICharacters(Array<Sint8> uriString) | String XmlWriter::encodeURICharacters(Array<Sint8> uriString) |
{ | { |
|
|
| |
for (Uint32 i=0; i<uriString.size(); i++) | for (Uint32 i=0; i<uriString.size(); i++) |
{ | { |
_encodeURIChar(encodedString, Char16(uriString[i])); |
_encodeURIChar(encodedString, uriString[i]); |
} | } |
| |
return encodedString; | return encodedString; |
|
|
{ | { |
String encodedString; | String encodedString; |
| |
|
/* i18n remove - did not handle surrogate pairs |
for (Uint32 i=0; i<uriString.size(); i++) | for (Uint32 i=0; i<uriString.size(); i++) |
{ | { |
_encodeURIChar(encodedString, uriString[i]); | _encodeURIChar(encodedString, uriString[i]); |
} | } |
|
*/ |
|
|
|
// See the "CIM Operations over HTTP" spec, section 3.3.2 and |
|
// 3.3.3, for the treatment of non US-ASCII (UTF-8) chars |
|
|
|
// First, convert to UTF-8 (include handling of surrogate pairs) |
|
Array<Sint8> utf8; |
|
for (Uint32 i = 0; i < uriString.size(); i++) |
|
{ |
|
Uint16 c = uriString[i]; |
|
|
|
if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || |
|
((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) |
|
{ |
|
Char16 highSurrogate = uriString[i]; |
|
Char16 lowSurrogate = uriString[++i]; |
|
|
|
_appendSurrogatePair(utf8, Uint16(highSurrogate),Uint16(lowSurrogate)); |
|
} |
|
else |
|
{ |
|
_appendChar(utf8, uriString[i]); |
|
} |
|
} |
|
|
|
// Second, escape the non HTTP-safe chars |
|
for (Uint32 i=0; i<utf8.size(); i++) |
|
{ |
|
_encodeURIChar(encodedString, utf8[i]); |
|
} |
| |
return encodedString; | return encodedString; |
} | } |