Imported Upstream version 2.38.1
[platform/upstream/libxml++.git] / docs / manual / html / ch01s02.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4 <title>UTF-8 and Glib::ustring</title>
5 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
6 <link rel="home" href="index.html" title="libxml++ - An XML Parser for C++">
7 <link rel="up" href="chapter-introduction.html" title="Chapter 1. libxml++">
8 <link rel="prev" href="chapter-introduction.html" title="Chapter 1. libxml++">
9 <link rel="next" href="ch01s03.html" title="Compilation and Linking">
10 </head>
11 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
12 <div class="navheader">
13 <table width="100%" summary="Navigation header">
14 <tr><th colspan="3" align="center">UTF-8 and Glib::ustring</th></tr>
15 <tr>
16 <td width="20%" align="left">
17 <a accesskey="p" href="chapter-introduction.html">Prev</a> </td>
18 <th width="60%" align="center">Chapter 1. libxml++</th>
19 <td width="20%" align="right"> <a accesskey="n" href="ch01s03.html">Next</a>
20 </td>
21 </tr>
22 </table>
23 <hr>
24 </div>
25 <div class="sect1">
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="idp66773776"></a>UTF-8 and Glib::ustring</h2></div></div></div>
28 <p>The libxml++ API takes, and gives, strings in the UTF-8 Unicode encoding, which can support all known languages and locales. This choice was made because, of the encodings that have this capability, UTF-8 is the most commonly accepted choice. UTF-8 is a multi-byte encoding, meaning that some characters use more than 1 byte. But for compatibility, old-fashioned 7-bit ASCII strings are unchanged when encoded as UTF-8, and UTF-8 strings do not contain null bytes which would cause old code to misjudge the number of bytes. For these reasons, you can store a UTF-8 string in a std::string object. However, the std::string API will operate on that string in terms of bytes, instead of characters.</p>
29 <p>Because Standard C++ has no string class that can fully handle UTF-8, libxml++ uses the Glib::ustring class from the glibmm library. Glib::ustring has almost exactly the same API as std::string, but methods such as length() and operator[] deal with whole UTF-8 characters rather than raw bytes.</p>
30 <p>There are implicit conversions between std::string and Glib::ustring, so you can use std::string wherever you see a Glib::ustring in the API, if you really don't care about any locale other than English. However, that is unlikely in today's connected world.</p>
31 <p>glibmm also provides useful API to convert between encodings and locales.</p>
32 </div>
33 <div class="navfooter">
34 <hr>
35 <table width="100%" summary="Navigation footer">
36 <tr>
37 <td width="40%" align="left">
38 <a accesskey="p" href="chapter-introduction.html">Prev</a> </td>
39 <td width="20%" align="center"><a accesskey="u" href="chapter-introduction.html">Up</a></td>
40 <td width="40%" align="right"> <a accesskey="n" href="ch01s03.html">Next</a>
41 </td>
42 </tr>
43 <tr>
44 <td width="40%" align="left" valign="top">Chapter 1. libxml++ </td>
45 <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
46 <td width="40%" align="right" valign="top"> Compilation and Linking</td>
47 </tr>
48 </table>
49 </div>
50 </body>
51 </html>