TransliteratorWrapper() { UnicodeString basicID("Any-Latin ; NFKD; [:nonspacing mark:] Remove"); UnicodeString basicIDAccent("Any-Latin ; NFKC"); UErrorCode status = U_ZERO_ERROR; m_tl = Transliterator::createInstance(basicID, UTRANS_FORWARD, status); // Note that if the first createInstance fails, the status will cause the // second createInstance to also fail. m_tl_accent = Transliterator::createInstance(basicIDAccent, UTRANS_FORWARD, status); if (U_FAILURE(status)) { raise_warning(string(u_errorName(status))); //m_tl should be NULL if createInstance fails but better safe than sorry. m_tl = NULL; m_tl_accent = NULL; } }
/** * Given a Specs object, return a SingleID representing the * special inverse of that ID. If there is no special inverse * then return NULL. * @return a SingleID or NULL. Returned object always has * 'filter' field of NULL. */ TransliteratorIDParser::SingleID * TransliteratorIDParser::specsToSpecialInverse(const Specs & specs, UErrorCode & status) { if (0 != specs.source.caseCompare(ANY, U_FOLD_CASE_DEFAULT)) { return NULL; } init(status); UnicodeString * inverseTarget; umtx_lock(&LOCK); inverseTarget = (UnicodeString *) SPECIAL_INVERSES->get(specs.target); umtx_unlock(&LOCK); if (inverseTarget != NULL) { // If the original ID contained "Any-" then make the // special inverse "Any-Foo"; otherwise make it "Foo". // So "Any-NFC" => "Any-NFD" but "NFC" => "NFD". UnicodeString buf; if (specs.filter.length() != 0) { buf.append(specs.filter); } if (specs.sawSource) { buf.append(ANY).append(TARGET_SEP); } buf.append(*inverseTarget); UnicodeString basicID(ANY); basicID.append(TARGET_SEP).append(*inverseTarget); if (specs.variant.length() != 0) { buf.append(VARIANT_SEP).append(specs.variant); basicID.append(VARIANT_SEP).append(specs.variant); } return new SingleID(buf, basicID); } return NULL; }