|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-0E8206E9-4F1D-5DF5-8A69-9B0831061CFF" xml:lang="en"><title>Escape |
|
13 Encoding and Decoding</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p>This tutorial describes the steps to escape encoding and decoding. </p> |
|
15 <section><title>Introduction</title> <p>Reserved, unsafe and unreserved characters |
|
16 present a possibility of being interpreted incorrectly when used in the URIs. |
|
17 To avoid this, these characters must be escape encoded and decoded. </p> </section> |
|
18 <section><title>Escape encoding </title><p>URI encoding of a character consists |
|
19 of a "%" symbol, followed by two hexadecimal digits representing the octet |
|
20 code. For example, Space = decimal code point 32 in the ISO-Latin set. 32 |
|
21 decimal = 20 in hexadecimal. The URI encoded representation will be "%20" </p> <p> <xref href="GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51.dita#GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51/GUID-26C9B121-B619-33EF-98A3-E65787C3A9BF"><apiname>EscapeUtils::EscapeEncodeL()</apiname></xref> escape |
|
22 encodes the invalid and reserved characters in the data as escape triples. |
|
23 The reserved characters and the set of excluded characters specified by <xref href="http://www.ietf.org/rfc/rfc2396.txt" scope="external">RFC 2396</xref> (refer |
|
24 to the above table) form the entire set of excluded data. </p> <p>The following |
|
25 code fragment checks for the invalid and reserved characters in the authority |
|
26 component of an URI and returns the string with these characters escape encoded. |
|
27 For other modes as defined in <xref href="GUID-0B61C1D3-7DAB-3149-932F-1F96A84EDF42.dita"><apiname>TEscapeMode</apiname></xref>, refer to the |
|
28 table in <xref href="GUID-E0DC9706-AAC5-5950-86E8-D667A7AFCD49.dita#GUID-E0DC9706-AAC5-5950-86E8-D667A7AFCD49/GUID-B5EB7F55-60AF-5703-96F6-0C42A3D433EE">Reservered |
|
29 characters</xref> section. </p> <codeblock id="GUID-D0CBCEA3-59F2-50E0-AC4D-473FC5DF24E9" xml:space="preserve">HBufC16* encode = EscapeUtils::EscapeEncodeL(*decode, EscapeUtils::EEscapeAuth); |
|
30 CleanupStack::PushL(encode);//encode contains %20%3C%3E%23%25%22%7B%7D%7C%5C%5E%60 |
|
31 |
|
32 ......//use encode here |
|
33 |
|
34 CleanupStack::PopAndDestroy(encode); |
|
35 </codeblock> <p>Escape encoding is ideal during creation of URI from the components. </p> </section> |
|
36 <section><title>Escape decoding </title><p> <xref href="GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51.dita#GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51/GUID-B4149EF0-0E1D-3F80-9974-165DF17105E9"><apiname>EscapeUtils::EscapeDecodeL()</apiname></xref> escape |
|
37 decodes the data. This code escape decodes the data '<codeph>%20%3C%3E%23%25%22%7B%7D%7C%5C%5E%60</codeph>' |
|
38 to '<codeph><>#%\"{}|\\^</codeph>'. </p> <codeblock id="GUID-F0A7F46E-F5DF-52CE-8334-AD7789208F97" xml:space="preserve">_LIT(KEscapeEncoded, %20%3C%3E%23%25%22%7B%7D%7C%5C%5E%60); //data to decode |
|
39 HBufC16* decode = EscapeUtils::EscapeDecodeL(KEscapeEncoded); //contains <>#%\"{}|\\^` |
|
40 CleanupStack::PushL(decode); |
|
41 ........................... |
|
42 CleanupStack::PopAndDestroy(decode); |
|
43 </codeblock> <p>The URI must be split into its components before |
|
44 the escaped characters within the components are safely decoded. </p></section> |
|
45 </conbody><related-links> |
|
46 <link href="GUID-795B41AF-FBEA-56CE-AE20-EF17BE754723.dita"><linktext>HTTP Utilities |
|
47 Library Overview</linktext></link> |
|
48 <link href="GUID-853BFDC0-1993-5EFC-AA68-C9EA496EEF3F.dita"><linktext>Converting |
|
49 between Unicode and Utf8</linktext></link> |
|
50 <link href="GUID-E0DC9706-AAC5-5950-86E8-D667A7AFCD49.dita"><linktext>Reserved |
|
51 and unreserved characters</linktext></link> |
|
52 </related-links></concept> |