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

utf8bidireorder.cpp

00001 /******************************************************************************
00002 *
00003 * utf8cnormalizer - SWFilter decendant to perform reordering of UTF-8
00004 *                   text to visual order according to Unicode BiDi
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 <utf8bidireorder.h>
00017 
00018 UTF8BiDiReorder::UTF8BiDiReorder() {
00019 
00020         conv = ucnv_open("UTF-8", &err);
00021 
00022 }
00023 
00024 UTF8BiDiReorder::~UTF8BiDiReorder() {
00025         ucnv_close(conv);
00026 }
00027 
00028 char UTF8BiDiReorder::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00029 {
00030         UChar *ustr, *ustr2;
00031         
00032         int32_t len = strlen(text);
00033         ustr = new UChar[len]; //each char could become a surrogate pair
00034 
00035         // Convert UTF-8 string to UTF-16 (UChars)
00036         len = ucnv_toUChars(conv, ustr, len, text, -1, &err);
00037         ustr2 = new UChar[len];
00038 
00039         UBiDi* bidi = ubidi_openSized(len + 1, 0, &err);
00040         ubidi_setPara(bidi, ustr, len, UBIDI_DEFAULT_RTL, NULL, &err);
00041         len = ubidi_writeReordered(bidi, ustr2, len,
00042                 UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &err);
00043         ubidi_close(bidi);
00044 
00045 //        len = ubidi_writeReverse(ustr, len, ustr2, len,
00046 //                UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &err);
00047 
00048         ucnv_fromUChars(conv, text, maxlen, ustr2, len, &err);
00049 
00050         delete [] ustr2;
00051         delete [] ustr;
00052         return 0;
00053 }
00054 
00055 #endif

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