本文整理汇总了C++中U_SUCCESS函数的典型用法代码示例。如果您正苦于以下问题:C++ U_SUCCESS函数的具体用法?C++ U_SUCCESS怎么用?C++ U_SUCCESS使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了U_SUCCESS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_text_file
static void process_text_file(struct config_t *p_config)
{
char *line = 0;
char linebuf[1024];
xmlDoc *doc = xmlParseFile(p_config->conffile);
xmlNode *xml_node = xmlDocGetRootElement(doc);
long unsigned int token_count = 0;
long unsigned int line_count = 0;
UErrorCode status = U_ZERO_ERROR;
if (!xml_node)
{
printf("Could not parse XML config file '%s' \n",
p_config->conffile);
exit(1);
}
p_config->chain = icu_chain_xml_config(xml_node, 1, &status);
if (!p_config->chain || !U_SUCCESS(status))
{
printf("Could not set up ICU chain from config file '%s' \n",
p_config->conffile);
exit(1);
}
if (p_config->xmloutput)
fprintf(p_config->outfile,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<icu>\n"
"<tokens>\n");
/* read input lines for processing */
while ((line=fgets(linebuf, sizeof(linebuf)-1, p_config->infile)))
{
WRBUF sw = wrbuf_alloc();
WRBUF cdata = wrbuf_alloc();
int success = icu_chain_assign_cstr(p_config->chain, line, &status);
line_count++;
while (success && icu_chain_next_token(p_config->chain, &status))
{
if (U_FAILURE(status))
success = 0;
else
{
size_t start, len;
const char *sortkey = icu_chain_token_sortkey(p_config->chain);
icu_chain_get_org_info(p_config->chain, &start, &len);
wrbuf_rewind(sw);
wrbuf_puts_escaped(sw, sortkey);
token_count++;
if (p_config->xmloutput)
{
fprintf(p_config->outfile,
"<token id=\"%lu\" line=\"%lu\"",
token_count, line_count);
wrbuf_rewind(cdata);
wrbuf_xmlputs(cdata, icu_chain_token_norm(p_config->chain));
fprintf(p_config->outfile, " norm=\"%s\"",
wrbuf_cstr(cdata));
wrbuf_rewind(cdata);
wrbuf_xmlputs(cdata, icu_chain_token_display(p_config->chain));
fprintf(p_config->outfile, " display=\"%s\"",
wrbuf_cstr(cdata));
if (p_config->sortoutput)
{
wrbuf_rewind(cdata);
wrbuf_xmlputs(cdata, wrbuf_cstr(sw));
fprintf(p_config->outfile, " sortkey=\"%s\"",
wrbuf_cstr(cdata));
}
fprintf(p_config->outfile, "/>\n");
}
else
{
fprintf(p_config->outfile, "%lu %lu '%s' '%s'",
token_count,
line_count,
icu_chain_token_norm(p_config->chain),
icu_chain_token_display(p_config->chain));
if (p_config->sortoutput)
{
fprintf(p_config->outfile, " '%s'", wrbuf_cstr(sw));
}
if (p_config->org_output)
{
fprintf(p_config->outfile, " %ld+%ld",
(long) start, (long) len);
}
fprintf(p_config->outfile, "\n");
}
}
//.........这里部分代码省略.........
示例2: TestOpenDirect
//.........这里部分代码省略.........
/* falling back to default or root is ok */
errorCode=U_ZERO_ERROR;
} else if(0!=uprv_strcmp("idna_rules", ures_getLocale(idna_rules, &errorCode))) {
/* Opening this file will work in "files mode" on Windows and the Mac,
which have case insensitive file systems */
log_err("ures_open(\"idna_rules\") succeeded, should fail! Got: %s\n", u_errorName(errorCode));
}
ures_close(idna_rules);
/* ures_openDirect("translit_index_WronG") must fail */
idna_rules=ures_openDirect(NULL, "idna_rules_WronG", &errorCode);
if(U_FAILURE(errorCode)) {
errorCode=U_ZERO_ERROR;
} else {
log_err("ures_openDirect(\"idna_rules_WronG\") succeeded, should fail!\n");
}
ures_close(idna_rules);
errorCode = U_USING_FALLBACK_WARNING;;
idna_rules=ures_openDirect("testdata", "idna_rules", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("ures_openDirect(\"idna_rules\") failed when U_USING_FALLBACK_WARNING was set prior to call: %s\n", u_errorName(errorCode));
return;
}
ures_close(idna_rules);
/*
* ICU 3.6 has new resource bundle syntax and data for bundles that do not
* participate in locale fallback. Now,
* - ures_open() works like ures_openDirect() on a bundle with a top-level
* type of ":table(nofallback)" _if_ the bundle exists
* - ures_open() will continue to find a root bundle if the requested one
* does not exist, unlike ures_openDirect()
*
* Test with a different bundle than above to avoid confusion in the cache.
*/
/*
* verify that ures_open("casing"), which now has a nofallback declaration,
* does not enable fallbacks
*/
errorCode=U_ZERO_ERROR;
casing=ures_open("testdata", "casing", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("ures_open(\"casing\") failed: %s\n", u_errorName(errorCode));
return;
}
errorCode=U_ZERO_ERROR;
item=ures_getByKey(casing, "Info", NULL, &errorCode);
if(U_FAILURE(errorCode)) {
log_err("casing.getByKey(Info) failed - %s\n", u_errorName(errorCode));
} else {
ures_close(item);
}
errorCode=U_ZERO_ERROR;
item=ures_getByKey(casing, "ShortLanguage", NULL, &errorCode);
if(U_SUCCESS(errorCode)) {
log_err("casing.getByKey(root key) succeeded despite nofallback declaration - %s\n", u_errorName(errorCode));
ures_close(item);
}
ures_close(casing);
/*
* verify that ures_open("ne") finds the root bundle but
* ures_openDirect("ne") does not
*/
errorCode=U_ZERO_ERROR;
ne=ures_open("testdata", "ne", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("ures_open(\"ne\") failed (expected to get root): %s\n", u_errorName(errorCode));
}
if(errorCode!=U_USING_DEFAULT_WARNING || 0!=uprv_strcmp("root", ures_getLocale(ne, &errorCode))) {
log_err("ures_open(\"ne\") found something other than \"root\" - %s\n", u_errorName(errorCode));
}
ures_close(ne);
errorCode=U_ZERO_ERROR;
ne=ures_openDirect("testdata", "ne", &errorCode);
if(U_SUCCESS(errorCode)) {
log_data_err("ures_openDirect(\"ne\") succeeded unexpectedly\n");
ures_close(ne);
}
/* verify that ures_openDirect("te_IN") does not enable fallbacks */
errorCode=U_ZERO_ERROR;
te_IN=ures_openDirect("testdata", "te_IN", &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("ures_open(\"te_IN\") failed: %s\n", u_errorName(errorCode));
return;
}
errorCode=U_ZERO_ERROR;
item=ures_getByKey(te_IN, "ShortLanguage", NULL, &errorCode);
if(U_SUCCESS(errorCode)) {
log_err("te_IN.getByKey(root key) succeeded despite use of ures_openDirect() - %s\n", u_errorName(errorCode));
ures_close(item);
}
ures_close(te_IN);
}
示例3: ucase_getSingleton
UnicodeSet& UnicodeSet::closeOver(int32_t attribute) {
if (isFrozen() || isBogus()) {
return *this;
}
if (attribute & (USET_CASE_INSENSITIVE | USET_ADD_CASE_MAPPINGS)) {
const UCaseProps *csp = ucase_getSingleton();
{
UnicodeSet foldSet(*this);
UnicodeString str;
USetAdder sa = {
foldSet.toUSet(),
_set_add,
_set_addRange,
_set_addString,
NULL, // don't need remove()
NULL // don't need removeRange()
};
// start with input set to guarantee inclusion
// USET_CASE: remove strings because the strings will actually be reduced (folded);
// therefore, start with no strings and add only those needed
if (attribute & USET_CASE_INSENSITIVE) {
foldSet.strings->removeAllElements();
}
int32_t n = getRangeCount();
UChar32 result;
const UChar *full;
int32_t locCache = 0;
for (int32_t i=0; i<n; ++i) {
UChar32 start = getRangeStart(i);
UChar32 end = getRangeEnd(i);
if (attribute & USET_CASE_INSENSITIVE) {
// full case closure
for (UChar32 cp=start; cp<=end; ++cp) {
ucase_addCaseClosure(csp, cp, &sa);
}
} else {
// add case mappings
// (does not add long s for regular s, or Kelvin for k, for example)
for (UChar32 cp=start; cp<=end; ++cp) {
result = ucase_toFullLower(csp, cp, NULL, NULL, &full, "", &locCache);
addCaseMapping(foldSet, result, full, str);
result = ucase_toFullTitle(csp, cp, NULL, NULL, &full, "", &locCache);
addCaseMapping(foldSet, result, full, str);
result = ucase_toFullUpper(csp, cp, NULL, NULL, &full, "", &locCache);
addCaseMapping(foldSet, result, full, str);
result = ucase_toFullFolding(csp, cp, &full, 0);
addCaseMapping(foldSet, result, full, str);
}
}
}
if (strings != NULL && strings->size() > 0) {
if (attribute & USET_CASE_INSENSITIVE) {
for (int32_t j=0; j<strings->size(); ++j) {
str = *(const UnicodeString *) strings->elementAt(j);
str.foldCase();
if(!ucase_addStringCaseClosure(csp, str.getBuffer(), str.length(), &sa)) {
foldSet.add(str); // does not map to code points: add the folded string itself
}
}
} else {
Locale root("");
#if !UCONFIG_NO_BREAK_ITERATION
UErrorCode status = U_ZERO_ERROR;
BreakIterator *bi = BreakIterator::createWordInstance(root, status);
if (U_SUCCESS(status)) {
#endif
const UnicodeString *pStr;
for (int32_t j=0; j<strings->size(); ++j) {
pStr = (const UnicodeString *) strings->elementAt(j);
(str = *pStr).toLower(root);
foldSet.add(str);
#if !UCONFIG_NO_BREAK_ITERATION
(str = *pStr).toTitle(bi, root);
foldSet.add(str);
#endif
(str = *pStr).toUpper(root);
foldSet.add(str);
(str = *pStr).foldCase();
foldSet.add(str);
}
#if !UCONFIG_NO_BREAK_ITERATION
}
delete bi;
#endif
}
}
*this = foldSet;
}
}
return *this;
}
示例4: bundle
UnicodeString& U_EXPORT2 Transliterator::getDisplayName(const UnicodeString& id,
const Locale& inLocale,
UnicodeString& result) {
UErrorCode status = U_ZERO_ERROR;
ResourceBundle bundle(U_ICUDATA_TRANSLIT, inLocale, status);
// Suspend checking status until later...
result.truncate(0);
// Normalize the ID
UnicodeString source, target, variant;
UBool sawSource;
TransliteratorIDParser::IDtoSTV(id, source, target, variant, sawSource);
if (target.length() < 1) {
// No target; malformed id
return result;
}
if (variant.length() > 0) { // Change "Foo" to "/Foo"
variant.insert(0, VARIANT_SEP);
}
UnicodeString ID(source);
ID.append(TARGET_SEP).append(target).append(variant);
// build the char* key
if (uprv_isInvariantUString(ID.getBuffer(), ID.length())) {
char key[200];
uprv_strcpy(key, RB_DISPLAY_NAME_PREFIX);
int32_t length=(int32_t)uprv_strlen(RB_DISPLAY_NAME_PREFIX);
ID.extract(0, (int32_t)(sizeof(key)-length), key+length, (int32_t)(sizeof(key)-length), US_INV);
// Try to retrieve a UnicodeString from the bundle.
UnicodeString resString = bundle.getStringEx(key, status);
if (U_SUCCESS(status) && resString.length() != 0) {
return result = resString; // [sic] assign & return
}
#if !UCONFIG_NO_FORMATTING
// We have failed to get a name from the locale data. This is
// typical, since most transliterators will not have localized
// name data. The next step is to retrieve the MessageFormat
// pattern from the locale data and to use it to synthesize the
// name from the ID.
status = U_ZERO_ERROR;
resString = bundle.getStringEx(RB_DISPLAY_NAME_PATTERN, status);
if (U_SUCCESS(status) && resString.length() != 0) {
MessageFormat msg(resString, inLocale, status);
// Suspend checking status until later...
// We pass either 2 or 3 Formattable objects to msg.
Formattable args[3];
int32_t nargs;
args[0].setLong(2); // # of args to follow
args[1].setString(source);
args[2].setString(target);
nargs = 3;
// Use display names for the scripts, if they exist
UnicodeString s;
length=(int32_t)uprv_strlen(RB_SCRIPT_DISPLAY_NAME_PREFIX);
for (int j=1; j<=2; ++j) {
status = U_ZERO_ERROR;
uprv_strcpy(key, RB_SCRIPT_DISPLAY_NAME_PREFIX);
args[j].getString(s);
if (uprv_isInvariantUString(s.getBuffer(), s.length())) {
s.extract(0, sizeof(key)-length-1, key+length, (int32_t)sizeof(key)-length-1, US_INV);
resString = bundle.getStringEx(key, status);
if (U_SUCCESS(status)) {
args[j] = resString;
}
}
}
status = U_ZERO_ERROR;
FieldPosition pos; // ignored by msg
msg.format(args, nargs, result, pos, status);
if (U_SUCCESS(status)) {
result.append(variant);
return result;
}
}
#endif
}
// We should not reach this point unless there is something
// wrong with the build or the RB_DISPLAY_NAME_PATTERN has
// been deleted from the root RB_LOCALE_ELEMENTS resource.
result = ID;
return result;
}
示例5: fprintf
//.........这里部分代码省略.........
case UCHAR_SIMPLE_LOWERCASE_MAPPING:
props.slc=U_SENTINEL;
break;
case UCHAR_SIMPLE_TITLECASE_MAPPING:
props.stc=U_SENTINEL;
break;
case UCHAR_SIMPLE_UPPERCASE_MAPPING:
props.suc=U_SENTINEL;
break;
case UCHAR_CASE_FOLDING:
props.cf.remove();
break;
case UCHAR_LOWERCASE_MAPPING:
props.lc.remove();
break;
case UCHAR_TITLECASE_MAPPING:
props.tc.remove();
break;
case UCHAR_UPPERCASE_MAPPING:
props.uc.remove();
break;
case UCHAR_SCRIPT_EXTENSIONS:
props.scx.clear();
break;
default:
fprintf(stderr,
"error in preparsed UCD: '%s' is not a valid default value on line %ld\n",
field, (long)lineNumber);
errorCode=U_PARSE_ERROR;
}
} else {
char c;
switch(prop) {
case UCHAR_NUMERIC_VALUE:
props.numericValue=v;
c=*v;
if('0'<=c && c<='9' && v[1]==0) {
props.digitValue=c-'0';
} else {
props.digitValue=-1;
}
break;
case UCHAR_NAME:
props.name=v;
break;
case UCHAR_AGE:
u_versionFromString(props.age, v); // Writes 0.0.0.0 if v is not numeric.
break;
case UCHAR_BIDI_MIRRORING_GLYPH:
props.bmg=parseCodePoint(v, errorCode);
break;
case UCHAR_BIDI_PAIRED_BRACKET:
props.bpb=parseCodePoint(v, errorCode);
break;
case UCHAR_SIMPLE_CASE_FOLDING:
props.scf=parseCodePoint(v, errorCode);
break;
case UCHAR_SIMPLE_LOWERCASE_MAPPING:
props.slc=parseCodePoint(v, errorCode);
break;
case UCHAR_SIMPLE_TITLECASE_MAPPING:
props.stc=parseCodePoint(v, errorCode);
break;
case UCHAR_SIMPLE_UPPERCASE_MAPPING:
props.suc=parseCodePoint(v, errorCode);
break;
case UCHAR_CASE_FOLDING:
parseString(v, props.cf, errorCode);
break;
case UCHAR_LOWERCASE_MAPPING:
parseString(v, props.lc, errorCode);
break;
case UCHAR_TITLECASE_MAPPING:
parseString(v, props.tc, errorCode);
break;
case UCHAR_UPPERCASE_MAPPING:
parseString(v, props.uc, errorCode);
break;
case PPUCD_NAME_ALIAS:
props.nameAlias=v;
break;
case PPUCD_CONDITIONAL_CASE_MAPPINGS:
case PPUCD_TURKIC_CASE_FOLDING:
// No need to parse their values: They are hardcoded in the runtime library.
break;
case UCHAR_SCRIPT_EXTENSIONS:
parseScriptExtensions(v, props.scx, errorCode);
break;
default:
// Ignore unhandled properties.
return TRUE;
}
}
if(U_SUCCESS(errorCode)) {
newValues.add((UChar32)prop);
return TRUE;
} else {
return FALSE;
}
}
示例6: if
const Normalizer2 *
Normalizer2::getInstance(const char *packageName,
const char *name,
UNormalization2Mode mode,
UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) {
return NULL;
}
if(name==NULL || *name==0) {
errorCode=U_ILLEGAL_ARGUMENT_ERROR;
return NULL;
}
const Norm2AllModes *allModes=NULL;
if(packageName==NULL) {
if(0==uprv_strcmp(name, "nfc")) {
allModes=Norm2AllModes::getNFCInstance(errorCode);
} else if(0==uprv_strcmp(name, "nfkc")) {
allModes=Norm2AllModes::getNFKCInstance(errorCode);
} else if(0==uprv_strcmp(name, "nfkc_cf")) {
allModes=Norm2AllModes::getNFKC_CFInstance(errorCode);
}
}
if(allModes==NULL && U_SUCCESS(errorCode)) {
{
Mutex lock;
if(cache!=NULL) {
allModes=(Norm2AllModes *)uhash_get(cache, name);
}
}
if(allModes==NULL) {
ucln_common_registerCleanup(UCLN_COMMON_LOADED_NORMALIZER2, uprv_loaded_normalizer2_cleanup);
LocalPointer<Norm2AllModes> localAllModes(
Norm2AllModes::createInstance(packageName, name, errorCode));
if(U_SUCCESS(errorCode)) {
Mutex lock;
if(cache==NULL) {
cache=uhash_open(uhash_hashChars, uhash_compareChars, NULL, &errorCode);
if(U_FAILURE(errorCode)) {
return NULL;
}
uhash_setKeyDeleter(cache, uprv_free);
uhash_setValueDeleter(cache, deleteNorm2AllModes);
}
void *temp=uhash_get(cache, name);
if(temp==NULL) {
int32_t keyLength= static_cast<int32_t>(uprv_strlen(name)+1);
char *nameCopy=(char *)uprv_malloc(keyLength);
if(nameCopy==NULL) {
errorCode=U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
uprv_memcpy(nameCopy, name, keyLength);
allModes=localAllModes.getAlias();
uhash_put(cache, nameCopy, localAllModes.orphan(), &errorCode);
} else {
// race condition
allModes=(Norm2AllModes *)temp;
}
}
}
}
if(allModes!=NULL && U_SUCCESS(errorCode)) {
switch(mode) {
case UNORM2_COMPOSE:
return &allModes->comp;
case UNORM2_DECOMPOSE:
return &allModes->decomp;
case UNORM2_FCD:
return &allModes->fcd;
case UNORM2_COMPOSE_CONTIGUOUS:
return &allModes->fcc;
default:
break; // do nothing
}
}
return NULL;
}
示例7: initicu
PyMODINIT_FUNC
initicu(void)
{
PyObject* m;
UVersionInfo ver, uver;
UErrorCode status = U_ZERO_ERROR;
char version[U_MAX_VERSION_STRING_LENGTH+1] = {0}, uversion[U_MAX_VERSION_STRING_LENGTH+5] = {0};
if (sizeof(Py_UNICODE) != 2 && sizeof(Py_UNICODE) != 4) {
PyErr_SetString(PyExc_RuntimeError, "This module only works on python versions <= 3.2");
return;
}
u_init(&status);
if (U_FAILURE(status)) {
PyErr_SetString(PyExc_RuntimeError, u_errorName(status));
return;
}
u_getVersion(ver);
u_versionToString(ver, version);
u_getUnicodeVersion(uver);
u_versionToString(uver, uversion);
if (PyType_Ready(&icu_CollatorType) < 0)
return;
m = Py_InitModule3("icu", icu_methods,
"Wrapper for the ICU internationalization library");
Py_INCREF(&icu_CollatorType);
PyModule_AddObject(m, "Collator", (PyObject *)&icu_CollatorType);
// uint8_t must be the same size as char
PyModule_AddIntConstant(m, "ok", (U_SUCCESS(status) && sizeof(uint8_t) == sizeof(char)) ? 1 : 0);
PyModule_AddStringConstant(m, "icu_version", version);
PyModule_AddStringConstant(m, "unicode_version", uversion);
ADDUCONST(USET_SPAN_NOT_CONTAINED);
ADDUCONST(USET_SPAN_CONTAINED);
ADDUCONST(USET_SPAN_SIMPLE);
ADDUCONST(UCOL_DEFAULT);
ADDUCONST(UCOL_PRIMARY);
ADDUCONST(UCOL_SECONDARY);
ADDUCONST(UCOL_TERTIARY);
ADDUCONST(UCOL_DEFAULT_STRENGTH);
ADDUCONST(UCOL_QUATERNARY);
ADDUCONST(UCOL_IDENTICAL);
ADDUCONST(UCOL_OFF);
ADDUCONST(UCOL_ON);
ADDUCONST(UCOL_SHIFTED);
ADDUCONST(UCOL_NON_IGNORABLE);
ADDUCONST(UCOL_LOWER_FIRST);
ADDUCONST(UCOL_UPPER_FIRST);
ADDUCONST(UNORM_NONE);
ADDUCONST(UNORM_NFD);
ADDUCONST(UNORM_NFKD);
ADDUCONST(UNORM_NFC);
ADDUCONST(UNORM_DEFAULT);
ADDUCONST(UNORM_NFKC);
ADDUCONST(UNORM_FCD);
}
示例8: deleteHash
void
CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status) {
if (U_FAILURE(status)) {
return;
}
if (fPluralCountToCurrencyUnitPattern) {
deleteHash(fPluralCountToCurrencyUnitPattern);
}
fPluralCountToCurrencyUnitPattern = initHash(status);
if (U_FAILURE(status)) {
return;
}
UErrorCode ec = U_ZERO_ERROR;
UResourceBundle *rb = ures_open(NULL, loc.getName(), &ec);
rb = ures_getByKey(rb, gNumberElementsTag, rb, &ec);
rb = ures_getByKey(rb, gLatnTag, rb, &ec);
rb = ures_getByKey(rb, gPatternsTag, rb, &ec);
int32_t ptnLen;
const UChar* numberStylePattern = ures_getStringByKeyWithFallback(rb, gDecimalFormatTag, &ptnLen, &ec);
int32_t numberStylePatternLen = ptnLen;
const UChar* negNumberStylePattern = NULL;
int32_t negNumberStylePatternLen = 0;
// TODO: Java
// parse to check whether there is ";" separator in the numberStylePattern
UBool hasSeparator = false;
if (U_SUCCESS(ec)) {
for (int32_t styleCharIndex = 0; styleCharIndex < ptnLen; ++styleCharIndex) {
if (numberStylePattern[styleCharIndex] == gNumberPatternSeparator) {
hasSeparator = true;
// split the number style pattern into positive and negative
negNumberStylePattern = numberStylePattern + styleCharIndex + 1;
negNumberStylePatternLen = ptnLen - styleCharIndex - 1;
numberStylePatternLen = styleCharIndex;
}
}
}
ures_close(rb);
if (U_FAILURE(ec)) {
return;
}
UResourceBundle *currRb = ures_open(U_ICUDATA_CURR, loc.getName(), &ec);
UResourceBundle *currencyRes = ures_getByKeyWithFallback(currRb, gCurrUnitPtnTag, NULL, &ec);
#ifdef CURRENCY_PLURAL_INFO_DEBUG
std::cout << "in set up\n";
#endif
StringEnumeration* keywords = fPluralRules->getKeywords(ec);
if (U_SUCCESS(ec)) {
const char* pluralCount;
while ((pluralCount = keywords->next(NULL, ec)) != NULL) {
if ( U_SUCCESS(ec) ) {
int32_t ptnLen;
UErrorCode err = U_ZERO_ERROR;
const UChar* patternChars = ures_getStringByKeyWithFallback(
currencyRes, pluralCount, &ptnLen, &err);
if (U_SUCCESS(err) && ptnLen > 0) {
UnicodeString* pattern = new UnicodeString(patternChars, ptnLen);
#ifdef CURRENCY_PLURAL_INFO_DEBUG
char result_1[1000];
pattern->extract(0, pattern->length(), result_1, "UTF-8");
std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n";
#endif
pattern->findAndReplace(gPart0,
UnicodeString(numberStylePattern, numberStylePatternLen));
pattern->findAndReplace(gPart1, gTripleCurrencySign);
if (hasSeparator) {
UnicodeString negPattern(patternChars, ptnLen);
negPattern.findAndReplace(gPart0,
UnicodeString(negNumberStylePattern, negNumberStylePatternLen));
negPattern.findAndReplace(gPart1, gTripleCurrencySign);
pattern->append(gNumberPatternSeparator);
pattern->append(negPattern);
}
#ifdef CURRENCY_PLURAL_INFO_DEBUG
pattern->extract(0, pattern->length(), result_1, "UTF-8");
std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n";
#endif
fPluralCountToCurrencyUnitPattern->put(UnicodeString(pluralCount), pattern, status);
}
}
}
}
delete keywords;
ures_close(currencyRes);
ures_close(currRb);
}
示例9: UnicodeSet
//------------------------------------------------------------------------------
//
// scanSet Construct a UnicodeSet from the text at the current scan
// position. Advance the scan position to the first character
// after the set.
//
// A new RBBI setref node referring to the set is pushed onto the node
// stack.
//
// The scan position is normally under the control of the state machine
// that controls rule parsing. UnicodeSets, however, are parsed by
// the UnicodeSet constructor, not by the RBBI rule parser.
//
//------------------------------------------------------------------------------
void RBBIRuleScanner::scanSet() {
UnicodeSet *uset;
ParsePosition pos;
int startPos;
int i;
if (U_FAILURE(*fRB->fStatus)) {
return;
}
pos.setIndex(fScanIndex);
startPos = fScanIndex;
UErrorCode localStatus = U_ZERO_ERROR;
uset = new UnicodeSet(fRB->fRules, pos, USET_IGNORE_SPACE,
fSymbolTable,
localStatus);
if (uset == NULL) {
localStatus = U_MEMORY_ALLOCATION_ERROR;
}
if (U_FAILURE(localStatus)) {
// TODO: Get more accurate position of the error from UnicodeSet's return info.
// UnicodeSet appears to not be reporting correctly at this time.
#ifdef RBBI_DEBUG
RBBIDebugPrintf("UnicodeSet parse postion.ErrorIndex = %d\n", pos.getIndex());
#endif
error(localStatus);
delete uset;
return;
}
// Verify that the set contains at least one code point.
//
if (uset->isEmpty()) {
// This set is empty.
// Make it an error, because it almost certainly is not what the user wanted.
// Also, avoids having to think about corner cases in the tree manipulation code
// that occurs later on.
error(U_BRK_RULE_EMPTY_SET);
delete uset;
return;
}
// Advance the RBBI parse postion over the UnicodeSet pattern.
// Don't just set fScanIndex because the line/char positions maintained
// for error reporting would be thrown off.
i = pos.getIndex();
for (;;) {
if (fNextIndex >= i) {
break;
}
nextCharLL();
}
if (U_SUCCESS(*fRB->fStatus)) {
RBBINode *n;
n = pushNewNode(RBBINode::setRef);
n->fFirstPos = startPos;
n->fLastPos = fNextIndex;
fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
// findSetFor() serves several purposes here:
// - Adopts storage for the UnicodeSet, will be responsible for deleting.
// - Mantains collection of all sets in use, needed later for establishing
// character categories for run time engine.
// - Eliminates mulitiple instances of the same set.
// - Creates a new uset node if necessary (if this isn't a duplicate.)
findSetFor(n->fText, n, uset);
}
}
示例10: tlist
/**
* Convert the elements of the 'list' vector, which are SingleID
* objects, into actual Transliterator objects. In the course of
* this, some (or all) entries may be removed. If all entries
* are removed, the NULL transliterator will be added.
*
* Delete entries with empty basicIDs; these are generated by
* elements like "(A)" in the forward direction, or "A()" in
* the reverse. THIS MAY RESULT IN AN EMPTY VECTOR. Convert
* SingleID entries to actual transliterators.
*
* @param list vector of SingleID objects. On exit, vector
* of one or more Transliterators.
* @return new value of insertIndex. The index will shift if
* there are empty items, like "(Lower)", with indices less than
* insertIndex.
*/
void TransliteratorIDParser::instantiateList(UVector& list,
UErrorCode& ec) {
UVector tlist(ec);
if (U_FAILURE(ec)) {
goto RETURN;
}
tlist.setDeleter(_deleteTransliteratorTrIDPars);
Transliterator* t;
int32_t i;
for (i=0; i<=list.size(); ++i) { // [sic]: i<=list.size()
// We run the loop too long by one, so we can
// do an insert after the last element
if (i==list.size()) {
break;
}
SingleID* single = (SingleID*) list.elementAt(i);
if (single->basicID.length() != 0) {
t = single->createInstance();
if (t == NULL) {
ec = U_INVALID_ID;
goto RETURN;
}
tlist.addElement(t, ec);
if (U_FAILURE(ec)) {
delete t;
goto RETURN;
}
}
}
// An empty list is equivalent to a NULL transliterator.
if (tlist.size() == 0) {
t = createBasicInstance(UnicodeString(TRUE, ANY_NULL, 8), NULL);
if (t == NULL) {
// Should never happen
ec = U_INTERNAL_TRANSLITERATOR_ERROR;
}
tlist.addElement(t, ec);
if (U_FAILURE(ec)) {
delete t;
}
}
RETURN:
UObjectDeleter *save = list.setDeleter(_deleteSingleID);
list.removeAllElements();
if (U_SUCCESS(ec)) {
list.setDeleter(_deleteTransliteratorTrIDPars);
while (tlist.size() > 0) {
t = (Transliterator*) tlist.orphanElementAt(0);
list.addElement(t, ec);
if (U_FAILURE(ec)) {
delete t;
list.removeAllElements();
break;
}
}
}
list.setDeleter(save);
}
示例11: utext_setNativeIndex
int32_t
ThaiBreakEngine::divideUpDictionaryRange( UText *text,
int32_t rangeStart,
int32_t rangeEnd,
UStack &foundBreaks ) const {
if ((rangeEnd - rangeStart) < THAI_MIN_WORD_SPAN) {
return 0; // Not enough characters for two words
}
uint32_t wordsFound = 0;
int32_t wordLength;
int32_t current;
UErrorCode status = U_ZERO_ERROR;
PossibleWord words[THAI_LOOKAHEAD];
UChar32 uc;
utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) {
wordLength = 0;
// Look for candidate words at the current position
int candidates = words[wordsFound%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd);
// If we found exactly one, use that
if (candidates == 1) {
wordLength = words[wordsFound%THAI_LOOKAHEAD].acceptMarked(text);
wordsFound += 1;
}
// If there was more than one, see which one can take us forward the most words
else if (candidates > 1) {
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
goto foundBest;
}
do {
int wordsMatched = 1;
if (words[(wordsFound+1)%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) > 0) {
if (wordsMatched < 2) {
// Followed by another dictionary word; mark first word as a good candidate
words[wordsFound%THAI_LOOKAHEAD].markCurrent();
wordsMatched = 2;
}
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
goto foundBest;
}
// See if any of the possible second words is followed by a third word
do {
// If we find a third word, stop right away
if (words[(wordsFound+2)%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd)) {
words[wordsFound%THAI_LOOKAHEAD].markCurrent();
goto foundBest;
}
}
while (words[(wordsFound+1)%THAI_LOOKAHEAD].backUp(text));
}
}
while (words[wordsFound%THAI_LOOKAHEAD].backUp(text));
foundBest:
wordLength = words[wordsFound%THAI_LOOKAHEAD].acceptMarked(text);
wordsFound += 1;
}
// We come here after having either found a word or not. We look ahead to the
// next word. If it's not a dictionary word, we will combine it withe the word we
// just found (if there is one), but only if the preceding word does not exceed
// the threshold.
// The text iterator should now be positioned at the end of the word we found.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && wordLength < THAI_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize
if (words[wordsFound%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) <= 0
&& (wordLength == 0
|| words[wordsFound%THAI_LOOKAHEAD].longestPrefix() < THAI_PREFIX_COMBINE_THRESHOLD)) {
// Look for a plausible word boundary
//TODO: This section will need a rework for UText.
int32_t remaining = rangeEnd - (current+wordLength);
UChar32 pc = utext_current32(text);
int32_t chars = 0;
for (;;) {
utext_next32(text);
uc = utext_current32(text);
// TODO: Here we're counting on the fact that the SA languages are all
// in the BMP. This should get fixed with the UText rework.
chars += 1;
if (--remaining <= 0) {
break;
}
if (fEndWordSet.contains(pc) && fBeginWordSet.contains(uc)) {
// Maybe. See if it's in the dictionary.
// NOTE: In the original Apple code, checked that the next
// two characters after uc were not 0x0E4C THANTHAKHAT before
// checking the dictionary. That is just a performance filter,
// but it's not clear it's faster than checking the trie.
int candidates = words[(wordsFound+1)%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd);
//.........这里部分代码省略.........
示例12: U_SUCCESS
UBool
FieldPositionIteratorHandler::isRecording(void) const {
return U_SUCCESS(status);
}
示例13: ucnv_swapAliases
//.........这里部分代码省略.........
if(count<=STACK_ROW_CAPACITY) {
tempTable.rows=rows;
tempTable.resort=resort;
} else {
tempTable.rows=(TempRow *)uprv_malloc(count*sizeof(TempRow)+count*2);
if(tempTable.rows==NULL) {
udata_printError(ds, "ucnv_swapAliases(): unable to allocate memory for sorting tables (max length: %u)\n",
count);
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
return 0;
}
tempTable.resort=(uint16_t *)(tempTable.rows+count);
}
if(ds->outCharset==U_ASCII_FAMILY) {
tempTable.stripForCompare=ucnv_io_stripASCIIForCompare;
} else /* U_EBCDIC_FAMILY */ {
tempTable.stripForCompare=ucnv_io_stripEBCDICForCompare;
}
/*
* Sort unique aliases+mapped names.
*
* We need to sort the list again by outCharset strings because they
* sort differently for different charset families.
* First we set up a temporary table with the string indexes and
* sorting indexes and sort that.
* Then we permutate and copy/swap the actual values.
*/
p=inTable+offsets[aliasListIndex];
q=outTable+offsets[aliasListIndex];
p2=inTable+offsets[untaggedConvArrayIndex];
q2=outTable+offsets[untaggedConvArrayIndex];
for(i=0; i<count; ++i) {
tempTable.rows[i].strIndex=ds->readUInt16(p[i]);
tempTable.rows[i].sortIndex=(uint16_t)i;
}
uprv_sortArray(tempTable.rows, (int32_t)count, sizeof(TempRow),
io_compareRows, &tempTable,
FALSE, pErrorCode);
if(U_SUCCESS(*pErrorCode)) {
/* copy/swap/permutate items */
if(p!=q) {
for(i=0; i<count; ++i) {
oldIndex=tempTable.rows[i].sortIndex;
ds->swapArray16(ds, p+oldIndex, 2, q+i, pErrorCode);
ds->swapArray16(ds, p2+oldIndex, 2, q2+i, pErrorCode);
}
} else {
/*
* If we swap in-place, then the permutation must use another
* temporary array (tempTable.resort)
* before the results are copied to the outBundle.
*/
uint16_t *r=tempTable.resort;
for(i=0; i<count; ++i) {
oldIndex=tempTable.rows[i].sortIndex;
ds->swapArray16(ds, p+oldIndex, 2, r+i, pErrorCode);
}
uprv_memcpy(q, r, 2*count);
for(i=0; i<count; ++i) {
oldIndex=tempTable.rows[i].sortIndex;
ds->swapArray16(ds, p2+oldIndex, 2, r+i, pErrorCode);
}
uprv_memcpy(q2, r, 2*count);
}
}
if(tempTable.rows!=rows) {
uprv_free(tempTable.rows);
}
if(U_FAILURE(*pErrorCode)) {
udata_printError(ds, "ucnv_swapAliases().uprv_sortArray(%u items) failed\n",
count);
return 0;
}
/* swap remaining 16-bit values */
ds->swapArray16(ds,
inTable+offsets[converterListIndex],
2*(int32_t)(offsets[aliasListIndex]-offsets[converterListIndex]),
outTable+offsets[converterListIndex],
pErrorCode);
ds->swapArray16(ds,
inTable+offsets[taggedAliasArrayIndex],
2*(int32_t)(offsets[stringTableIndex]-offsets[taggedAliasArrayIndex]),
outTable+offsets[taggedAliasArrayIndex],
pErrorCode);
}
}
return headerSize+2*(int32_t)topOffset;
}
示例14: uprv_strlen
UnicodeString&
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString& result) const {
UnicodeString resultName;
const char* lang = locale.getLanguage();
if (uprv_strlen(lang) == 0) {
lang = "root";
}
const char* script = locale.getScript();
const char* country = locale.getCountry();
const char* variant = locale.getVariant();
UBool hasScript = uprv_strlen(script) > 0;
UBool hasCountry = uprv_strlen(country) > 0;
UBool hasVariant = uprv_strlen(variant) > 0;
if (dialectHandling == ULDN_DIALECT_NAMES) {
char buffer[ULOC_FULLNAME_CAPACITY];
do { // loop construct is so we can break early out of search
if (hasScript && hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
hasCountry = FALSE;
break;
}
}
if (hasScript) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
break;
}
}
if (hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasCountry = FALSE;
break;
}
}
} while (FALSE);
}
if (resultName.isBogus() || resultName.isEmpty()) {
localeIdName(lang, resultName);
}
UnicodeString resultRemainder;
UnicodeString temp;
StringEnumeration *e = NULL;
UErrorCode status = U_ZERO_ERROR;
if (hasScript) {
resultRemainder.append(scriptDisplayName(script, temp));
}
if (hasCountry) {
appendWithSep(resultRemainder, regionDisplayName(country, temp));
}
if (hasVariant) {
appendWithSep(resultRemainder, variantDisplayName(variant, temp));
}
e = locale.createKeywords(status);
if (e && U_SUCCESS(status)) {
UnicodeString temp2;
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
keyDisplayName(key, temp);
keyValueDisplayName(key, value, temp2);
if (temp2 != UnicodeString(value, -1, US_INV)) {
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
UnicodeString temp3;
Formattable data[] = {
temp,
temp2
};
FieldPosition fpos;
status = U_ZERO_ERROR;
keyTypeFormat->format(data, 2, temp3, fpos, status);
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
.append((UChar)0x3d /* = */)
.append(temp2);
}
}
delete e;
}
if (!resultRemainder.isEmpty()) {
Formattable data[] = {
resultName,
resultRemainder
//.........这里部分代码省略.........
示例15: unorm_iterate
static int32_t
unorm_iterate(UCharIterator *src, UBool forward,
UChar *dest, int32_t destCapacity,
UNormalizationMode mode, int32_t options,
UBool doNormalize, UBool *pNeededToNormalize,
UErrorCode *pErrorCode) {
const Normalizer2 *n2=Normalizer2Factory::getInstance(mode, *pErrorCode);
const UnicodeSet *uni32;
if(options&UNORM_UNICODE_3_2) {
uni32=uniset_getUnicode32Instance(*pErrorCode);
} else {
uni32=NULL; // unused
}
FilteredNormalizer2 fn2(*n2, *uni32);
if(options&UNORM_UNICODE_3_2) {
n2=&fn2;
}
if(U_FAILURE(*pErrorCode)) {
return 0;
}
if( destCapacity<0 || (dest==NULL && destCapacity>0) ||
src==NULL
) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
if(pNeededToNormalize!=NULL) {
*pNeededToNormalize=FALSE;
}
if(!(forward ? src->hasNext(src) : src->hasPrevious(src))) {
return u_terminateUChars(dest, destCapacity, 0, pErrorCode);
}
UnicodeString buffer;
UChar32 c;
if(forward) {
/* get one character and ignore its properties */
buffer.append(uiter_next32(src));
/* get all following characters until we see a boundary */
while((c=uiter_next32(src))>=0) {
if(n2->hasBoundaryBefore(c)) {
/* back out the latest movement to stop at the boundary */
src->move(src, -U16_LENGTH(c), UITER_CURRENT);
break;
} else {
buffer.append(c);
}
}
} else {
while((c=uiter_previous32(src))>=0) {
/* always write this character to the front of the buffer */
buffer.insert(0, c);
/* stop if this just-copied character is a boundary */
if(n2->hasBoundaryBefore(c)) {
break;
}
}
}
UnicodeString destString(dest, 0, destCapacity);
if(buffer.length()>0 && doNormalize) {
n2->normalize(buffer, destString, *pErrorCode).extract(dest, destCapacity, *pErrorCode);
if(pNeededToNormalize!=NULL && U_SUCCESS(*pErrorCode)) {
*pNeededToNormalize= destString!=buffer;
}
return destString.length();
} else {
/* just copy the source characters */
return buffer.extract(dest, destCapacity, *pErrorCode);
}
}