Symbian3/PDK/Source/GUID-0E8206E9-4F1D-5DF5-8A69-9B0831061CFF.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Tue, 30 Mar 2010 11:56:28 +0100
changeset 5 f345bda72bc4
parent 3 46218c8b8afa
child 14 578be2adaf3e
permissions -rw-r--r--
Week 12 contribution of PDK documentation_content. See release notes for details. Fixes Bug 2054, Bug 1583, Bug 381, Bug 390, Bug 463, Bug 1897, Bug 344, Bug 1319, Bug 394, Bug 1520, Bug 1522, Bug 1892"

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-0E8206E9-4F1D-5DF5-8A69-9B0831061CFF" xml:lang="en"><title>Escape
Encoding and Decoding</title><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>This tutorial describes the steps to escape encoding and decoding. </p>
<section><title>Introduction</title> <p>Reserved, unsafe and unreserved characters
present a possibility of being interpreted incorrectly when used in the URIs.
To avoid this, these characters must be escape encoded and decoded. </p> </section>
<section><title>Escape encoding </title><p>URI encoding of a character consists
of a "%" symbol, followed by two hexadecimal digits representing the octet
code. For example, Space = decimal code point 32 in the ISO-Latin set. 32
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
encodes the invalid and reserved characters in the data as escape triples.
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
to the above table) form the entire set of excluded data. </p> <p>The following
code fragment checks for the invalid and reserved characters in the authority
component of an URI and returns the string with these characters escape encoded.
For other modes as defined in <xref href="GUID-0B61C1D3-7DAB-3149-932F-1F96A84EDF42.dita"><apiname>TEscapeMode</apiname></xref>, refer to the
table in <xref href="GUID-E0DC9706-AAC5-5950-86E8-D667A7AFCD49.dita#GUID-E0DC9706-AAC5-5950-86E8-D667A7AFCD49/GUID-B5EB7F55-60AF-5703-96F6-0C42A3D433EE">Reservered
characters</xref> section. </p> <codeblock id="GUID-D0CBCEA3-59F2-50E0-AC4D-473FC5DF24E9" xml:space="preserve">HBufC16* encode = EscapeUtils::EscapeEncodeL(*decode,  EscapeUtils::EEscapeAuth);
CleanupStack::PushL(encode);//encode contains %20%3C%3E%23%25%22%7B%7D%7C%5C%5E%60

......//use encode here

CleanupStack::PopAndDestroy(encode);
</codeblock> <p>Escape encoding is ideal during creation of URI from the components. </p> </section>
<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
decodes the data. This code escape decodes the data '<codeph>%20%3C%3E%23%25%22%7B%7D%7C%5C%5E%60</codeph>'
to '<codeph>&lt;&gt;#%\"{}|\\^</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
HBufC16* decode = EscapeUtils::EscapeDecodeL(KEscapeEncoded); //contains &lt;&gt;#%\"{}|\\^`
CleanupStack::PushL(decode);
...........................
CleanupStack::PopAndDestroy(decode);
          </codeblock> <p>The URI must be split into its components before
the escaped characters within the components are safely decoded. </p></section>
</conbody><related-links>
<link href="GUID-795B41AF-FBEA-56CE-AE20-EF17BE754723.dita"><linktext>HTTP Utilities
Library Overview</linktext></link>
<link href="GUID-853BFDC0-1993-5EFC-AA68-C9EA496EEF3F.dita"><linktext>Converting
between Unicode and Utf8</linktext></link>
<link href="GUID-E0DC9706-AAC5-5950-86E8-D667A7AFCD49.dita"><linktext>Reserved
and unreserved characters</linktext></link>
</related-links></concept>