aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/utf8nfc_8cpp-source.html
blob: 6451121061df1d78efa8272856b73587c24b67bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>utf8nfc.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>utf8nfc.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment">*</font>
00003 <font class="comment">* utf8nfc - SWFilter decendant to perform NFC (canonical composition</font>
00004 <font class="comment">*                   normalization) on UTF-8 text</font>
00005 <font class="comment">*/</font>
00006 
00007 <font class="preprocessor">#ifdef _ICU_</font>
00008 <font class="preprocessor"></font>
00009 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00010 <font class="preprocessor">#include &lt;string.h&gt;</font>
00011 
00012 <font class="preprocessor">#ifdef __GNUC__</font>
00013 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unixstr.h&gt;</font>
00014 <font class="preprocessor">#endif</font>
00015 <font class="preprocessor"></font>
00016 <font class="preprocessor">#include &lt;utf8nfc.h&gt;</font>
00017 
00018 UTF8NFC::UTF8NFC() {
00019         conv = ucnv_open(<font class="stringliteral">"UTF-8"</font>, &amp;err);
00020 }
00021 
00022 UTF8NFC::~UTF8NFC() {
00023          ucnv_close(conv);
00024 }
00025 
00026 <font class="keywordtype">char</font> UTF8NFC::ProcessText(<font class="keywordtype">char</font> *text, <font class="keywordtype">int</font> maxlen, <font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *key, <font class="keyword">const</font> <a class="code" href="class_s_w_module.html">SWModule</a> *module)
00027 {
00028         int32_t len = strlen(text) * 2;
00029         source = <font class="keyword">new</font> UChar[len + 1]; <font class="comment">//each char could become a surrogate pair</font>
00030 
00031         <font class="comment">// Convert UTF-8 string to UTF-16 (UChars)</font>
00032         len = ucnv_toUChars(conv, source, len, text, -1, &amp;err);
00033         target = <font class="keyword">new</font> UChar[len + 1];
00034 
00035         <font class="comment">//canonical composition</font>
00036         unorm_normalize(source, len, UNORM_NFC, 0, target, len, &amp;err);
00037 
00038         ucnv_fromUChars(conv, text, maxlen, target, -1, &amp;err);
00039 
00040         <font class="keyword">delete</font> [] source;
00041         <font class="keyword">delete</font> [] target;
00042 
00043         <font class="keywordflow">return</font> 0;
00044 }
00045 
00046 <font class="preprocessor">#endif</font>
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>