本文整理汇总了C++中UnicodeString::compare方法的典型用法代码示例。如果您正苦于以下问题:C++ UnicodeString::compare方法的具体用法?C++ UnicodeString::compare怎么用?C++ UnicodeString::compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnicodeString
的用法示例。
在下文中一共展示了UnicodeString::compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCanonicalCountry
UnicodeString& U_EXPORT2
ZoneMeta::getSingleCountry(const UnicodeString &tzid, UnicodeString &country) {
UErrorCode status = U_ZERO_ERROR;
// Get canonical country for the zone
getCanonicalCountry(tzid, country);
if (!country.isEmpty()) {
UResourceBundle *supplementalDataBundle = ures_openDirect(NULL, gSupplementalData, &status);
UResourceBundle *zoneFormatting = ures_getByKey(supplementalDataBundle, gZoneFormattingTag, NULL, &status);
UResourceBundle *multizone = ures_getByKey(zoneFormatting, gMultizoneTag, NULL, &status);
if (U_SUCCESS(status)) {
while (ures_hasNext(multizone)) {
int32_t len;
const UChar* multizoneCountry = ures_getNextString(multizone, &len, NULL, &status);
if (country.compare(multizoneCountry, len) == 0) {
// Included in the multizone country list
country.remove();
break;
}
}
}
ures_close(multizone);
ures_close(zoneFormatting);
ures_close(supplementalDataBundle);
}
return country;
}
示例2:
void
ChoiceFormat::parse(const UnicodeString& text,
Formattable& result,
ParsePosition& status) const
{
// find the best number (defined as the one with the longest parse)
int32_t start = status.getIndex();
int32_t furthest = start;
double bestNumber = uprv_getNaN();
double tempNumber = 0.0;
for (int i = 0; i < fCount; ++i) {
int32_t len = fChoiceFormats[i].length();
if (text.compare(start, len, fChoiceFormats[i]) == 0) {
status.setIndex(start + len);
tempNumber = fChoiceLimits[i];
if (status.getIndex() > furthest) {
furthest = status.getIndex();
bestNumber = tempNumber;
if (furthest == text.length())
break;
}
}
}
status.setIndex(furthest);
if (status.getIndex() == start) {
status.setErrorIndex(furthest);
}
result.setDouble(bestNumber);
}
示例3: initializeMetaToOlson
UnicodeString& U_EXPORT2
ZoneMeta::getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString ®ion, UnicodeString &result) {
initializeMetaToOlson();
UBool isSet = FALSE;
if (gMetaToOlson != NULL) {
UErrorCode status = U_ZERO_ERROR;
UChar mzidUChars[ZID_KEY_MAX];
mzid.extract(mzidUChars, ZID_KEY_MAX, status);
if (U_SUCCESS(status) && status!=U_STRING_NOT_TERMINATED_WARNING) {
UVector *mappings = (UVector*)uhash_get(gMetaToOlson, mzidUChars);
if (mappings != NULL) {
// Find a preferred time zone for the given region.
for (int32_t i = 0; i < mappings->size(); i++) {
MetaToOlsonMappingEntry *olsonmap = (MetaToOlsonMappingEntry*)mappings->elementAt(i);
if (region.compare(olsonmap->territory, -1) == 0) {
result.setTo(olsonmap->id);
isSet = TRUE;
break;
} else if (u_strcmp(olsonmap->territory, gWorld) == 0) {
result.setTo(olsonmap->id);
isSet = TRUE;
}
}
}
}
}
if (!isSet) {
result.remove();
}
return result;
}
示例4: SkipToIdentifier
int pelet::SkipToIdentifier(BufferClass *buffer, UnicodeString identifier) {
bool end = false;
// add semicolon to make checks easier
identifier.append(';');
UChar c = *buffer->Current;
while (!end) {
/*
* read one line at a time. If the line is the identifier we'll stop. If we reach the
* end, then this heredoc in unterminated.
* be careful; do NOT store buffer->Current since it may change at any after buffer->AppendToLexeme
* is called
*/
UnicodeString line;
while (c != 0 && c != '\n' && c != '\r') {
line.append(c);
// only fill buffer when we its close to being filled up; this will prevent
// useless copying of the buffer to remove slack
if ((buffer->Limit - buffer->Current) < 2) {
buffer->AppendToLexeme(1);
}
c = *(++buffer->Current);
}
if (c == 0) {
end = true;
return T_ERROR_UNTERMINATED_STRING;
}
// since we are eating up a newline, otherwise line numbering in lint errors
// will be wrong
buffer->IncrementLine();
bool hasEndingSemicolon = true;
if (!line.endsWith(UNICODE_STRING(";", 1))) {
line.append(UNICODE_STRING(";", 1));
hasEndingSemicolon = false;
}
if (line.compare(identifier) == 0) {
end = true;
// semicolons and newlines are NOT part of the nowdoc; the parser will look for semicolons
// semicolon is OPTIONAL for heredoc / nowdoc
if (hasEndingSemicolon) {
buffer->Current--;
}
}
else {
if ((buffer->Limit - buffer->Current) < 2) {
buffer->AppendToLexeme(1);
}
c = *(++buffer->Current);
}
}
return 0;
}
示例5: registerSTV
/**
* Register a source-target/variant in the specDAG. Variant may be
* empty, but source and target must not be.
*/
void TransliteratorRegistry::registerSTV(const UnicodeString& source,
const UnicodeString& target,
const UnicodeString& variant) {
// assert(source.length() > 0);
// assert(target.length() > 0);
UErrorCode status = U_ZERO_ERROR;
Hashtable *targets = (Hashtable*) specDAG.get(source);
if (targets == 0) {
int32_t size = 3;
if (source.compare(ANY,3) == 0) {
size = ANY_TARGETS_INIT_SIZE;
} else if (source.compare(LAT,3) == 0) {
size = LAT_TARGETS_INIT_SIZE;
}
targets = new Hashtable(TRUE, size, status);
if (U_FAILURE(status) || targets == NULL) {
return;
}
specDAG.put(source, targets, status);
}
int32_t variantListIndex = variantList.indexOf((void*) &variant, 0);
if (variantListIndex < 0) {
if (variantList.size() >= VARIANT_LIST_MAX_SIZE) {
// can't handle any more variants
return;
}
UnicodeString *variantEntry = new UnicodeString(variant);
if (variantEntry != NULL) {
variantList.addElement(variantEntry, status);
if (U_SUCCESS(status)) {
variantListIndex = variantList.size() - 1;
}
}
if (variantListIndex < 0) {
return;
}
}
uint32_t addMask = 1 << variantListIndex;
uint32_t varMask = targets->geti(target);
targets->puti(target, varMask | addMask, status);
}
示例6: indexOrNegativeFromString
int32_t StandardPlural::indexOrNegativeFromString(const UnicodeString &keyword) {
switch (keyword.length()) {
case 3:
if (keyword.compare(gOne, 3) == 0) {
return ONE;
} else if (keyword.compare(gTwo, 3) == 0) {
return TWO;
} else if (keyword.compare(gFew, 3) == 0) {
return FEW;
}
break;
case 4:
if (keyword.compare(gMany, 4) == 0) {
return MANY;
} else if (keyword.compare(gZero, 4) == 0) {
return ZERO;
}
break;
case 5:
if (keyword.compare(gOther, 5) == 0) {
return OTHER;
}
break;
default:
break;
}
return -1;
}
示例7: switch
UnicodeString t4p::RowToSqlInsertClass::CreateStatement(t4p::DatabaseTagClass::Drivers driver) const {
UnicodeString query;
UnicodeString columnDelim;
switch (driver) {
case t4p::DatabaseTagClass::MYSQL:
columnDelim = '`';
break;
case t4p::DatabaseTagClass::SQLITE:
columnDelim = '"';
break;
}
bool doMultiLine = MULTI_LINE == LineMode;
query = UNICODE_STRING_SIMPLE("INSERT INTO ");
query += TableName;
query += UNICODE_STRING_SIMPLE(" (");
for (size_t i = 0; i < CheckedColumns.size(); ++i) {
if (doMultiLine && (i % 5) == 0) {
query += UNICODE_STRING_SIMPLE("\n");
}
query += columnDelim + CheckedColumns[i] + columnDelim;
if (i < (CheckedColumns.size() - 1)) {
query += UNICODE_STRING_SIMPLE(",");
}
}
if (doMultiLine) {
query += UNICODE_STRING_SIMPLE("\n");
}
query += UNICODE_STRING_SIMPLE(" ) VALUES (");
for (size_t i = 0; i < CheckedValues.size(); ++i) {
if (doMultiLine && (i % 5) == 0) {
query += UNICODE_STRING_SIMPLE("\n");
}
UnicodeString val = CheckedValues[i];
if (val.compare(UNICODE_STRING_SIMPLE("<NULL>")) == 0) {
val = UNICODE_STRING_SIMPLE("NULL");
} else {
val = UNICODE_STRING_SIMPLE("'") + val + UNICODE_STRING_SIMPLE("'");
}
query += val;
if (i < (CheckedValues.size() - 1)) {
query += UNICODE_STRING_SIMPLE(", ");
}
}
query += UNICODE_STRING_SIMPLE(");");
return query;
}
示例8: doTest
void RBBIAPITest::doTest(UnicodeString& testString, int32_t start, int32_t gotoffset, int32_t expectedOffset, const char* expectedString){
UnicodeString selected;
UnicodeString expected=CharsToUnicodeString(expectedString);
if(gotoffset != expectedOffset)
errln((UnicodeString)"ERROR:****returned #" + gotoffset + (UnicodeString)" instead of #" + expectedOffset);
if(start <= gotoffset){
testString.extractBetween(start, gotoffset, selected);
}
else{
testString.extractBetween(gotoffset, start, selected);
}
if(selected.compare(expected) != 0)
errln(prettify((UnicodeString)"ERROR:****selected \"" + selected + "\" instead of \"" + expected + "\""));
else
logln(prettify("****selected \"" + selected + "\""));
}
示例9: findKeyword
// -------------------------------------
// Finds the string, s, in the string array, list.
int32_t MessageFormat::findKeyword(const UnicodeString& s,
const UChar * const *list)
{
if (s.length() == 0)
return 0; // default
UnicodeString buffer = s;
// Trims the space characters and turns all characters
// in s to lower case.
buffer.trim().toLower("");
for (int32_t i = 0; list[i]; ++i) {
if (!buffer.compare(list[i], u_strlen(list[i]))) {
return i;
}
}
return -1;
}
示例10: setDictionaryFlag
//-------------------------------------------------------------------------------------
//
// RangeDescriptor::setDictionaryFlag
//
// Character Category Numbers that include characters from
// the original Unicode Set named "dictionary" have bit 14
// set to 1. The RBBI runtime engine uses this to trigger
// use of the word dictionary.
//
// This function looks through the Unicode Sets that it
// (the range) includes, and sets the bit in fNum when
// "dictionary" is among them.
//
// TODO: a faster way would be to find the set node for
// "dictionary" just once, rather than looking it
// up by name every time.
//
//-------------------------------------------------------------------------------------
void RangeDescriptor::setDictionaryFlag() {
int i;
for (i=0; i<this->fIncludesSets->size(); i++) {
RBBINode *usetNode = (RBBINode *)fIncludesSets->elementAt(i);
UnicodeString setName;
RBBINode *setRef = usetNode->fParent;
if (setRef != NULL) {
RBBINode *varRef = setRef->fParent;
if (varRef != NULL && varRef->fType == RBBINode::varRef) {
setName = varRef->fText;
}
}
if (setName.compare(UNICODE_STRING("dictionary", 10)) == 0) { // TODO: no string literals.
this->fNum |= 0x4000;
break;
}
}
}
示例11: findInStringArray
static int32_t findInStringArray(UResourceBundle* array, const UnicodeString& id, UErrorCode &status)
{
UnicodeString copy;
const UChar *u;
int32_t len;
int32_t start = 0;
int32_t limit = ures_getSize(array);
int32_t mid;
int32_t lastMid = INT32_MAX;
if(U_FAILURE(status) || (limit < 1)) {
return -1;
}
U_DEBUG_TZ_MSG(("fisa: Looking for %s, between %d and %d\n", U_DEBUG_TZ_STR(UnicodeString(id).getTerminatedBuffer()), start, limit));
for (;;) {
mid = (int32_t)((start + limit) / 2);
if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */
}
lastMid = mid;
u = ures_getStringByIndex(array, mid, &len, &status);
if (U_FAILURE(status)) {
break;
}
U_DEBUG_TZ_MSG(("tz: compare to %s, %d .. [%d] .. %d\n", U_DEBUG_TZ_STR(u), start, mid, limit));
copy.setTo(TRUE, u, len);
int r = id.compare(copy);
if(r==0) {
U_DEBUG_TZ_MSG(("fisa: found at %d\n", mid));
return mid;
} else if(r<0) {
limit = mid;
} else {
start = mid;
}
}
U_DEBUG_TZ_MSG(("fisa: not found\n"));
return -1;
}
示例12:
UnicodeString t4p::RowToPhpClass::CreatePhpArray() {
UnicodeString code;
UnicodeString endCode;
if (SYNTAX_KEYWORD == ArraySyntax) {
code += UNICODE_STRING_SIMPLE("array (\n");
endCode = UNICODE_STRING_SIMPLE(")\n");
} else {
code += UNICODE_STRING_SIMPLE("[\n");
endCode = UNICODE_STRING_SIMPLE("]\n");
}
for (size_t i = 0; i < CheckedColumns.size(); ++i) {
code += UNICODE_STRING_SIMPLE(" ");
code += UNICODE_STRING_SIMPLE("'");
code += CheckedColumns[i];
code += UNICODE_STRING_SIMPLE("'");
code += UNICODE_STRING_SIMPLE(" => ");
UnicodeString val;
if (VALUES_ROW == CopyValues && i < CheckedValues.size()) {
val = CheckedValues[i];
if (val.compare(UNICODE_STRING_SIMPLE("<NULL>")) == 0) {
code += UNICODE_STRING_SIMPLE("NULL");
} else {
code += UNICODE_STRING_SIMPLE("'");
code += val;
code += UNICODE_STRING_SIMPLE("'");
}
} else {
code += UNICODE_STRING_SIMPLE("''");
}
if (i < (CheckedColumns.size() - 1)) {
code += UNICODE_STRING_SIMPLE(",");
}
code += UNICODE_STRING_SIMPLE("\n");
}
code += endCode;
code += UNICODE_STRING_SIMPLE("\n");
return code;
}
示例13: parse
void RelativeDateFormat::parse( const UnicodeString& text,
Calendar& cal,
ParsePosition& pos) const {
// Can the fDateFormat parse it?
if(fDateFormat != NULL) {
ParsePosition aPos(pos);
fDateFormat->parse(text,cal,aPos);
if((aPos.getIndex() != pos.getIndex()) &&
(aPos.getErrorIndex()==-1)) {
pos=aPos; // copy the sub parse
return; // parsed subfmt OK
}
}
// Linear search the relative strings
for(int n=0; n<fDatesLen; n++) {
if(fDates[n].string != NULL &&
(0==text.compare(pos.getIndex(),
fDates[n].len,
fDates[n].string))) {
UErrorCode status = U_ZERO_ERROR;
// Set the calendar to now+offset
cal.setTime(Calendar::getNow(),status);
cal.add(UCAL_DATE,fDates[n].offset, status);
if(U_FAILURE(status)) {
// failure in setting calendar fields
pos.setErrorIndex(pos.getIndex()+fDates[n].len);
} else {
pos.setIndex(pos.getIndex()+fDates[n].len);
}
return;
}
}
// parse failed
}
示例14:
int32_t
ChoiceFormat::matchStringUntilLimitPart(
const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
const UnicodeString &source, int32_t sourceOffset) {
int32_t matchingSourceLength = 0;
const UnicodeString &msgString = pattern.getPatternString();
int32_t prevIndex = pattern.getPart(partIndex).getLimit();
for (;;) {
const MessagePattern::Part &part = pattern.getPart(++partIndex);
if (partIndex == limitPartIndex || part.getType() == UMSGPAT_PART_TYPE_SKIP_SYNTAX) {
int32_t index = part.getIndex();
int32_t length = index - prevIndex;
if (length != 0 && 0 != source.compare(sourceOffset, length, msgString, prevIndex, length)) {
return -1; // mismatch
}
matchingSourceLength += length;
if (partIndex == limitPartIndex) {
return matchingSourceLength;
}
prevIndex = part.getLimit(); // SKIP_SYNTAX
}
}
}
示例15: sizeof
//.........这里部分代码省略.........
* double currency sign or triple currency sign.
*/
int styleInNumberPattern = ((style == kIsoCurrencyStyle ||
style == kPluralCurrencyStyle) ?
kCurrencyStyle : style);
const UChar *patResStr = ures_getStringByIndex(numberPatterns, (int32_t)styleInNumberPattern, &patLen, &status);
// Creates the specified decimal format style of the desired locale.
pattern.setTo(TRUE, patResStr, patLen);
}
if (U_FAILURE(status) || symbolsToAdopt == NULL) {
goto cleanup;
}
if(style==kCurrencyStyle || style == kIsoCurrencyStyle){
const UChar* currPattern = symbolsToAdopt->getCurrencyPattern();
if(currPattern!=NULL){
pattern.setTo(currPattern, u_strlen(currPattern));
}
}
// Use numbering system cache hashtable
UMTX_CHECK(&nscacheMutex, (UBool)(cache != NumberingSystem_cache), getCache);
if (getCache) {
umtx_lock(&nscacheMutex);
cache = NumberingSystem_cache;
umtx_unlock(&nscacheMutex);
}
// Check cache we got, create if non-existant
status = U_ZERO_ERROR;
if (cache == NULL) {
cache = uhash_open(uhash_hashLong,
uhash_compareLong,
NULL,
&status);
if (cache == NULL || U_FAILURE(status)) {
// cache not created - out of memory
cache = NULL;
}
else {
// cache created
uhash_setValueDeleter(cache, deleteNumberingSystem);
// set final NumberingSystem_cache value
UHashtable* h = NULL;
UMTX_CHECK(&nscacheMutex, (UBool)(h != NumberingSystem_cache), getCache);
if (getCache) {
umtx_lock(&nscacheMutex);
h = NumberingSystem_cache;
umtx_unlock(&nscacheMutex);
}
if (h == NULL) {
umtx_lock(&nscacheMutex);
NumberingSystem_cache = h = cache;
cache = NULL;
ucln_i18n_registerCleanup(UCLN_I18N_NUMFMT, numfmt_cleanup);
umtx_unlock(&nscacheMutex);
}
if(cache != NULL) {
uhash_close(cache);
}
cache = h;