Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

utf8nfc.cpp

00001 /******************************************************************************
00002 *
00003 * utf8nfc - SWFilter decendant to perform NFC (canonical composition
00004 *                   normalization) on UTF-8 text
00005 */
00006 
00007 #ifdef _ICU_
00008 
00009 #include <stdlib.h>
00010 #include <string.h>
00011 
00012 #ifdef __GNUC__
00013 #include <unixstr.h>
00014 #endif
00015 
00016 #include <utf8nfc.h>
00017 
00018 UTF8NFC::UTF8NFC() {
00019         conv = ucnv_open("UTF-8", &err);
00020 }
00021 
00022 UTF8NFC::~UTF8NFC() {
00023          ucnv_close(conv);
00024 }
00025 
00026 char UTF8NFC::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00027 {
00028         int32_t len = strlen(text) * 2;
00029         source = new UChar[len + 1]; //each char could become a surrogate pair
00030 
00031         // Convert UTF-8 string to UTF-16 (UChars)
00032         len = ucnv_toUChars(conv, source, len, text, -1, &err);
00033         target = new UChar[len + 1];
00034 
00035         //canonical composition
00036         unorm_normalize(source, len, UNORM_NFC, 0, target, len, &err);
00037 
00038         ucnv_fromUChars(conv, text, maxlen, target, -1, &err);
00039 
00040         delete [] source;
00041         delete [] target;
00042 
00043         return 0;
00044 }
00045 
00046 #endif

Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by doxygen1.2.15