<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libmtp: /home/mandrake/rpm/BUILD/libmtp-1.0.2/src/unicode.c File Reference</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_afadb87d2fbfeb62b40078349a549d44.html">src</a> </div> </div> <div class="contents"> <h1>unicode.c File Reference</h1><code>#include <config.h></code><br/> <code>#include <stdlib.h></code><br/> <code>#include <string.h></code><br/> <code>#include "<a class="el" href="libmtp_8h_source.html">libmtp.h</a>"</code><br/> <code>#include "<a class="el" href="unicode_8h_source.html">unicode.h</a>"</code><br/> <code>#include "util.h"</code><br/> <code>#include "ptp.h"</code><br/> <table border="0" cellpadding="0" cellspacing="0"> <tr><td colspan="2"><h2>Defines</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="unicode_8c.html#adfd4d6129d983b4e02faacbf3ee5aed6">STRING_BUFFER_LENGTH</a> 1024</td></tr> <tr><td colspan="2"><h2>Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="unicode_8c.html#a4cd4877130c4725b964233f0727ee4d6">ucs2_strlen</a> (uint16_t const *const unicstr)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">char * </td><td class="memItemRight" valign="bottom"><a class="el" href="unicode_8c.html#ab4df4601f1707802059584f3567265bb">utf16_to_utf8</a> (<a class="el" href="structLIBMTP__mtpdevice__struct.html">LIBMTP_mtpdevice_t</a> *device, const uint16_t *unicstr)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">uint16_t * </td><td class="memItemRight" valign="bottom"><a class="el" href="unicode_8c.html#a343f3a62b855d9ff014afb733e4b392c">utf8_to_utf16</a> (<a class="el" href="structLIBMTP__mtpdevice__struct.html">LIBMTP_mtpdevice_t</a> *device, const char *localstr)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="unicode_8c.html#a2bda980f6207cb48ca2e8103f07dfb58">strip_7bit_from_utf8</a> (char *str)</td></tr> </table> <hr/><a name="_details"></a><h2>Detailed Description</h2> <p>This file contains general Unicode string manipulation functions. It mainly consist of functions for converting between UCS-2 (used on the devices) and UTF-8 (used by several applications).</p> <p>For a deeper understanding of Unicode encoding formats see the Wikipedia entries for <a href="http://en.wikipedia.org/wiki/UTF-16/UCS-2">UTF-16/UCS-2</a> and <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a>.</p> <p>Copyright (C) 2005-2009 Linus Walleij <<a href="mailto:triad@df.lth.se">triad@df.lth.se</a>></p> <p>This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</p> <p>This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</p> <p>You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. </p> <hr/><h2>Define Documentation</h2> <a class="anchor" id="adfd4d6129d983b4e02faacbf3ee5aed6"></a><!-- doxytag: member="unicode.c::STRING_BUFFER_LENGTH" ref="adfd4d6129d983b4e02faacbf3ee5aed6" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">#define STRING_BUFFER_LENGTH 1024</td> </tr> </table> </div> <div class="memdoc"> <p>The size of the buffer (in characters) used for creating string copies. </p> <p>Referenced by <a class="el" href="unicode_8c_source.html#l00078">utf16_to_utf8()</a>, and <a class="el" href="unicode_8c_source.html#l00111">utf8_to_utf16()</a>.</p> </div> </div> <hr/><h2>Function Documentation</h2> <a class="anchor" id="a2bda980f6207cb48ca2e8103f07dfb58"></a><!-- doxytag: member="unicode.c::strip_7bit_from_utf8" ref="a2bda980f6207cb48ca2e8103f07dfb58" args="(char *str)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void strip_7bit_from_utf8 </td> <td>(</td> <td class="paramtype">char * </td> <td class="paramname"> <em>str</em></td> <td> ) </td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>This helper function simply removes any consecutive chars > 0x7F and replace then with an underscore. In UTF-8 consequtive chars > 0x7F represent one single character so it has to be done like this (and it's elegant). It will only shrink the string in size so no copying is needed. </p> <p>Referenced by <a class="el" href="libmtp_8c_source.html#l06691">LIBMTP_Create_Folder()</a>.</p> </div> </div> <a class="anchor" id="a4cd4877130c4725b964233f0727ee4d6"></a><!-- doxytag: member="unicode.c::ucs2_strlen" ref="a4cd4877130c4725b964233f0727ee4d6" args="(uint16_t const *const unicstr)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int ucs2_strlen </td> <td>(</td> <td class="paramtype">uint16_t const *const </td> <td class="paramname"> <em>unicstr</em></td> <td> ) </td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Gets the length (in characters, not bytes) of a unicode UCS-2 string, eg a string which physically is 0x00 0x41 0x00 0x00 will return a value of 1.</p> <dl><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>unicstr</em> </td><td>a UCS-2 Unicode string </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>the length of the string, in number of characters. If you want to know the length in bytes, multiply this by two and add two (for zero terminator). </dd></dl> <p>Referenced by <a class="el" href="unicode_8c_source.html#l00078">utf16_to_utf8()</a>, and <a class="el" href="unicode_8c_source.html#l00111">utf8_to_utf16()</a>.</p> </div> </div> <a class="anchor" id="ab4df4601f1707802059584f3567265bb"></a><!-- doxytag: member="unicode.c::utf16_to_utf8" ref="ab4df4601f1707802059584f3567265bb" args="(LIBMTP_mtpdevice_t *device, const uint16_t *unicstr)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">char* utf16_to_utf8 </td> <td>(</td> <td class="paramtype"><a class="el" href="structLIBMTP__mtpdevice__struct.html">LIBMTP_mtpdevice_t</a> * </td> <td class="paramname"> <em>device</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">const uint16_t * </td> <td class="paramname"> <em>unicstr</em></td><td> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Converts a big-endian UTF-16 2-byte string to a UTF-8 string. Actually just a UCS-2 internal conversion routine that strips off the BOM if there is one.</p> <dl><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>device</em> </td><td>a pointer to the current device. </td></tr> <tr><td valign="top"></td><td valign="top"><em>unicstr</em> </td><td>the UTF-16 unicode string to convert </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>a UTF-8 string. </dd></dl> <p>References <a class="el" href="libmtp_8h_source.html#l00580">LIBMTP_mtpdevice_struct::params</a>, <a class="el" href="unicode_8c_source.html#l00048">STRING_BUFFER_LENGTH</a>, and <a class="el" href="unicode_8c_source.html#l00060">ucs2_strlen()</a>.</p> </div> </div> <a class="anchor" id="a343f3a62b855d9ff014afb733e4b392c"></a><!-- doxytag: member="unicode.c::utf8_to_utf16" ref="a343f3a62b855d9ff014afb733e4b392c" args="(LIBMTP_mtpdevice_t *device, const char *localstr)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">uint16_t* utf8_to_utf16 </td> <td>(</td> <td class="paramtype"><a class="el" href="structLIBMTP__mtpdevice__struct.html">LIBMTP_mtpdevice_t</a> * </td> <td class="paramname"> <em>device</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">const char * </td> <td class="paramname"> <em>localstr</em></td><td> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Converts a UTF-8 string to a big-endian UTF-16 2-byte string Actually just a UCS-2 internal conversion.</p> <dl><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>device</em> </td><td>a pointer to the current device. </td></tr> <tr><td valign="top"></td><td valign="top"><em>localstr</em> </td><td>the UTF-8 unicode string to convert </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>a UTF-16 string. </dd></dl> <p>References <a class="el" href="libmtp_8h_source.html#l00580">LIBMTP_mtpdevice_struct::params</a>, <a class="el" href="unicode_8c_source.html#l00048">STRING_BUFFER_LENGTH</a>, and <a class="el" href="unicode_8c_source.html#l00060">ucs2_strlen()</a>.</p> </div> </div> </div> <hr size="1"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> </body> </html>