/*
*****************************************************************
-* Copyright (c) 2002-2003, International Business Machines Corporation
+* Copyright (c) 2002-2011, International Business Machines Corporation
* and others. All Rights Reserved.
*****************************************************************
* Date Name Description
#include "uvector.h"
#include "tridpars.h"
#include "hash.h"
+#include "putilimp.h"
+#include "uinvchar.h"
//------------------------------------------------------------
// Constants
*/
static void U_CALLCONV
_deleteTransliterator(void *obj) {
- delete (Transliterator*) obj;
+ delete (icu::Transliterator*) obj;
}
U_CDECL_END
//------------------------------------------------------------
// AnyTransliterator
-const char AnyTransliterator::fgClassID=0;
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(AnyTransliterator)
AnyTransliterator::AnyTransliterator(const UnicodeString& id,
const UnicodeString& theTarget,
Transliterator(id, NULL),
targetScript(theTargetScript)
{
- cache = uhash_open(uhash_hashLong, uhash_compareLong, &ec);
+ cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &ec);
+ if (U_FAILURE(ec)) {
+ return;
+ }
uhash_setValueDeleter(cache, _deleteTransliterator);
target = theTarget;
{
// Don't copy the cache contents
UErrorCode ec = U_ZERO_ERROR;
- cache = uhash_open(uhash_hashLong, uhash_compareLong, &ec);
+ cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &ec);
+ if (U_FAILURE(ec)) {
+ return;
+ }
uhash_setValueDeleter(cache, _deleteTransliterator);
}
Transliterator* t = (Transliterator*) uhash_iget(cache, (int32_t) source);
if (t == NULL) {
UErrorCode ec = U_ZERO_ERROR;
- UnicodeString sourceName(uscript_getName(source), "");
+ UnicodeString sourceName(uscript_getName(source), -1, US_INV);
UnicodeString id(sourceName);
id.append(TARGET_SEP).append(target);
// Try to pivot around Latin, our most common script
id = sourceName;
- id.append(LATIN_PIVOT).append(target);
+ id.append(LATIN_PIVOT, -1).append(target);
t = Transliterator::createInstance(id, UTRANS_FORWARD, ec);
if (U_FAILURE(ec) || t == NULL) {
delete t;
/**
* Return the script code for a given name, or -1 if not found.
*/
-UScriptCode AnyTransliterator::scriptNameToCode(const UnicodeString& name) {
+static UScriptCode scriptNameToCode(const UnicodeString& name) {
char buf[128];
UScriptCode code;
UErrorCode ec = U_ZERO_ERROR;
-
- name.extract(0, 128, buf, 128, "");
- if (uscript_getCode(buf, &code, 1, &ec) != 1 ||
- U_FAILURE(ec)) {
+ int32_t nameLen = name.length();
+ UBool isInvariant = uprv_isInvariantUString(name.getBuffer(), nameLen);
+
+ if (isInvariant) {
+ name.extract(0, nameLen, buf, (int32_t)sizeof(buf), US_INV);
+ buf[127] = 0; // Make sure that we NULL terminate the string.
+ }
+ if (!isInvariant || uscript_getCode(buf, &code, 1, &ec) != 1 || U_FAILURE(ec))
+ {
code = USCRIPT_INVALID_CODE;
}
return code;
*/
void AnyTransliterator::registerIDs() {
- UErrorCode ec;
- Hashtable seen(TRUE);
+ UErrorCode ec = U_ZERO_ERROR;
+ Hashtable seen(TRUE, ec);
int32_t sourceCount = Transliterator::_countAvailableSources();
for (int32_t s=0; s<sourceCount; ++s) {
Transliterator::_getAvailableSource(s, source);
// Ignore the "Any" source
- if (source.caseCompare(ANY, 0 /*U_FOLD_CASE_DEFAULT*/) == 0) continue;
+ if (source.caseCompare(ANY, 3, 0 /*U_FOLD_CASE_DEFAULT*/) == 0) continue;
int32_t targetCount = Transliterator::_countAvailableTargets(source);
for (int32_t t=0; t<targetCount; ++t) {
Transliterator::_getAvailableVariant(v, source, target, variant);
UnicodeString id;
- TransliteratorIDParser::STVtoID(ANY, target, variant, id);
+ TransliteratorIDParser::STVtoID(UnicodeString(TRUE, ANY, 3), target, variant, id);
ec = U_ZERO_ERROR;
AnyTransliterator* t = new AnyTransliterator(id, target, variant,
targetScript, ec);
delete t;
} else {
Transliterator::_registerInstance(t);
- Transliterator::_registerSpecialInverse(target, NULL_ID, FALSE);
+ Transliterator::_registerSpecialInverse(target, UnicodeString(TRUE, NULL_ID, 4), FALSE);
}
}
}