Symbian3/SDK/Source/GUID-853BFDC0-1993-5EFC-AA68-C9EA496EEF3F.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 7 51a74ef9ed63
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?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-853BFDC0-1993-5EFC-AA68-C9EA496EEF3F" xml:lang="en"><title>Converting
between Unicode and UTF8</title><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>This tutorial describes the steps to convert between Unicode and UTF8. </p>
<section><title>Introduction</title> <p> <xref href="GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51.dita"><apiname>EscapeUtils</apiname></xref> escape
encodes and decodes unsafe data in URI. It also supports converting of Unicode
data (16-bit descriptor) into UTF8 data (8-bit descriptor) and vice-versa. </p> </section>
<section><title>Procedure</title> <p><b>Converting to UTF8 </b> </p> <p> <xref href="GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51.dita#GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51/GUID-4B9587D9-5DBF-3DD2-8792-BF37C18A1D50"><apiname> EscapeUtils::ConvertFromUnicodeToUtf8L() </apiname></xref> converts
the Unicode data into UTF8 format. </p> <codeblock id="GUID-0A646116-B483-5CE2-9B18-4308E2646FE0" xml:space="preserve">_LIT16(KUnicode, "Unicode string"); //data to be converted
    
HBufC8* utf8  = EscapeUtils::ConvertFromUnicodeToUtf8L(KUnicode);</codeblock> <p> <codeph>utf8</codeph> contains
the UTF8 form of the string. </p> <p><b>Converting to Unicode </b> </p> <p> <xref href="GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51.dita#GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51/GUID-0363432A-E064-3B44-B6C7-D17DA4CE58D5"><apiname> EscapeUtils::ConvertToUnicodeFromUtf8L()</apiname></xref> converts
the data from UTF8 format to Unicode. </p> <codeblock id="GUID-0AC63DF9-D4C0-548C-B7A9-2354CDC549CC" xml:space="preserve">_LIT8(KUtf8, "UTF-8 string"); // UTF8 string to be converted
    
HBufC16* unicode = EscapeUtils::ConvertToUnicodeFromUtf8L(KUtf8); // convert the srting to Unicode
          </codeblock> <p> <codeph>unicode</codeph> contains the Unicode form
of the string. </p> <p>Call <xref href="GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51.dita#GUID-9CC256C4-D4A2-3534-9B3C-2FBF1AAE5F51/GUID-BFDB092D-81AB-36D7-99F4-30A8F37566C3"><apiname>EscapeUtils::IsEscapeTriple</apiname></xref> to
check if the input data contains an escape triple. For example, <codeph>%2a</codeph>.
If there is a triple, its value is calculated and returned through the output
argument <codeph>HexVal</codeph>. If there is no escape triple, then this
argument is left unchanged. </p> <codeblock id="GUID-C6F09864-CCBA-5FF3-8A9D-66F0E7C74DE2" xml:space="preserve">_LIT(KEscapeTriple1, "%2a"); // input data containing escape triple
TInt KEscapeTriple1_value = 0x2a;
TInt HexVal;
EscapeUtils::IsEscapeTriple(KEscapeTriple1,HexVal); // escape triple value
//variable HexVal contains value 0x2a</codeblock> <p>The code above returns
'42' , the value of escape triple. </p> </section>
</conbody><related-links>
<link href="GUID-795B41AF-FBEA-56CE-AE20-EF17BE754723.dita"><linktext>HTTP Utilities
Library Overview</linktext></link>
<link href="GUID-0E8206E9-4F1D-5DF5-8A69-9B0831061CFF.dita"><linktext>Escape encoding
and decoding tutorial</linktext></link>
<link href="GUID-E0DC9706-AAC5-5950-86E8-D667A7AFCD49.dita"><linktext>Reserved
and unreserved characters</linktext></link>
</related-links></concept>