Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 122

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Glib::ustring</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Programming with gtkmm">
<link rel="up" href="chapter-basics.html" title="Chapter 3. Basics">
<link rel="prev" href="sec-signals-overview.html" title="Signals">
<link rel="next" href="sec-intermediate-types.html" title="Intermediate types">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Glib::ustring</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-signals-overview.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Chapter 3. Basics</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-intermediate-types.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Glib::ustring">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-basics-ustring"></a>Glib::ustring</h2></div></div></div>
<p>You might be surprised to learn that <span class="application">gtkmm</span> doesn't use <code class="classname">std::string</code> in it its interfaces. Instead it uses <code class="classname">Glib::ustring</code>, which is so similar and unobtrusive that you could actually pretend that each Glib::ustring is a <code class="classname">std::string</code> and ignore the rest of this section. But read on if you want to use languages other than English in your application.</p>
<p>std::string uses 8 bit per character, but 8 bits aren't enough to encode languages such as Arabic, Chinese, and Japanese. Although the encodings for these languages has now been specified by the Unicode Constortium, the C and C++ languages do not yet provide any standardised Unicode support. GTK+ and GNOME chose to implement Unicode using UTF-8, and that's what is wrapped by Glib::ustring. It provides almost exactly the same interface as std::string, along with automatic conversions to and from std::string.</p>
<p>One of the benefits of UTF-8 is that you don't need to use it unless you want to, so you don't need to retrofit all of your code at once. <code class="classname">std::string</code> will still work for 7-bit ASCII strings. But when you try to localize your application for languages like Chinese, for instance, you will start to see strange errors, and possible crashes. Then all you need to do is start using <code class="classname">Glib::ustring</code> instead.</p>
<p>Note that UTF-8 isn't compatible with 8-bit encodings like ISO-8859-1. For instance, German umlauts are not in the ASCII range and need more than 1 byte in the UTF-8 encoding. If your code contains 8-bit string literals, you have to convert them to UTF-8 (e.g. the Bavarian greeting "Grüß Gott" would be "Gr\xC3\xBC\xC3\x9F Gott").</p>
<p>You should avoid C-style pointer arithmetic, and functions such as strlen(). In UTF-8, each character might need anywhere from 1 to 6 bytes, so it's not possible to assume that the next byte is another character. <code class="classname">Glib::ustring</code> worries about the details of this for you so you can use methods such as Glib::ustring::substr() while still thinking in terms of characters instead of bytes.</p>
<p>Unlike the Windows UCS-2 Unicode solution, this does not require any special compiler options to process string literals, and it does not result in Unicode executables and libraries which are incompatible with ASCII ones.</p>
<p><a class="ulink" href="http://library.gnome.org/devel/glibmm/unstable/classGlib_1_1ustring.html" target="_top">Reference</a></p>
<p>See the <a class="link" href="chapter-internationalization.html" title="Chapter 24. Internationalization and Localization">Internationalization</a> section for information about providing the UTF-8 string literals.</p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-signals-overview.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-basics.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-intermediate-types.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Signals </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Intermediate types</td>
</tr>
</table>
</div>
</body>
</html>