1
/******************************************************************************
3
* utf8nfkd - SWFilter descendant to perform NFKD (compatability decomposition
4
* normalization) on UTF-8 text
7
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
8
* CrossWire Bible Society
10
* Tempe, AZ 85280-2528
12
* This program is free software; you can redistribute it and/or modify it
13
* under the terms of the GNU General Public License as published by the
14
* Free Software Foundation version 2.
16
* This program is distributed in the hope that it will be useful, but
17
* WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* General Public License for more details.
34
UTF8NFKD::UTF8NFKD() {
35
conv = ucnv_open("UTF-8", &err);
38
UTF8NFKD::~UTF8NFKD() {
42
char UTF8NFKD::processText(SWBuf &text, const SWKey *key, const SWModule *module)
44
if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
47
int32_t len = 5 + text.length() * 5;
48
source = new UChar[len + 1]; //each char could become a surrogate pair
50
// Convert UTF-8 string to UTF-16 (UChars)
51
int32_t ulen = ucnv_toUChars(conv, source, len, text.c_str(), -1, &err);
52
target = new UChar[len + 1];
54
//compatability decomposition
55
ulen = unorm_normalize(source, ulen, UNORM_NFKD, 0, target, len, &err);
58
len = ucnv_fromUChars(conv, text.getRawData(), len, target, ulen, &err);