本文整理汇总了C++中UVector::addElement方法的典型用法代码示例。如果您正苦于以下问题:C++ UVector::addElement方法的具体用法?C++ UVector::addElement怎么用?C++ UVector::addElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UVector
的用法示例。
在下文中一共展示了UVector::addElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UVector
/**
* Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region
* hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any
* sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type
* "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. )
*/
StringEnumeration*
Region::getContainedRegions( URegionType type, UErrorCode &status ) const {
umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); // returns immediately if U_FAILURE(status)
if (U_FAILURE(status)) {
return NULL;
}
UVector *result = new UVector(NULL, uhash_compareChars, status);
StringEnumeration *cr = getContainedRegions(status);
for ( int32_t i = 0 ; i < cr->count(status) ; i++ ) {
const char *id = cr->next(NULL,status);
const Region *r = Region::getInstance(id,status);
if ( r->getType() == type ) {
result->addElement((void *)&r->idStr,status);
} else {
StringEnumeration *children = r->getContainedRegions(type, status);
for ( int32_t j = 0 ; j < children->count(status) ; j++ ) {
const char *id2 = children->next(NULL,status);
const Region *r2 = Region::getInstance(id2,status);
result->addElement((void *)&r2->idStr,status);
}
delete children;
}
}
delete cr;
StringEnumeration* resultEnumeration = new RegionNameEnumeration(result,status);
delete result;
return resultEnumeration;
}
示例2: getUniquePatterns
void CompactData::getUniquePatterns(UVector &output, UErrorCode &status) const {
U_ASSERT(output.isEmpty());
// NOTE: In C++, this is done more manually with a UVector.
// In Java, we can take advantage of JDK HashSet.
for (auto pattern : patterns) {
if (pattern == nullptr || pattern == USE_FALLBACK) {
continue;
}
// Insert pattern into the UVector if the UVector does not already contain the pattern.
// Search the UVector from the end since identical patterns are likely to be adjacent.
for (int32_t i = output.size() - 1; i >= 0; i--) {
if (u_strcmp(pattern, static_cast<const UChar *>(output[i])) == 0) {
goto continue_outer;
}
}
// The string was not found; add it to the UVector.
// ANDY: This requires a const_cast. Why?
output.addElement(const_cast<UChar *>(pattern), status);
continue_outer:
continue;
}
}
示例3: UVector
UVector *AlphabeticIndex::firstStringsInScript(UErrorCode &status) {
if (U_FAILURE(status)) {
return NULL;
}
UVector *dest = new UVector(status);
if (dest == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
dest->setDeleter(uprv_deleteUObject);
const UChar *src = HACK_FIRST_CHARS_IN_SCRIPTS;
const UChar *limit = src + LENGTHOF(HACK_FIRST_CHARS_IN_SCRIPTS);
do {
if (U_FAILURE(status)) {
return dest;
}
UnicodeString *str = new UnicodeString(src, -1);
if (str == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return dest;
}
dest->addElement(str, status);
src += str->length() + 1;
} while (src < limit);
return dest;
}
示例4: valueDeleter
void
CharacterNode::addValue(void *value, UObjectDeleter *valueDeleter, UErrorCode &status) {
if (U_FAILURE(status)) {
if (valueDeleter) {
valueDeleter(value);
}
return;
}
if (fValues == NULL) {
fValues = value;
} else {
// At least one value already.
if (!fHasValuesVector) {
// There is only one value so far, and not in a vector yet.
// Create a vector and add the old value.
UVector *values = new UVector(valueDeleter, NULL, DEFAULT_CHARACTERNODE_CAPACITY, status);
if (U_FAILURE(status)) {
if (valueDeleter) {
valueDeleter(value);
}
return;
}
values->addElement(fValues, status);
fValues = values;
fHasValuesVector = TRUE;
}
// Add the new value.
((UVector *)fValues)->addElement(value, status);
}
}
示例5: UVector
UVector*
RuleBasedTimeZone::copyRules(UVector* source) {
if (source == NULL) {
return NULL;
}
UErrorCode ec = U_ZERO_ERROR;
int32_t size = source->size();
UVector *rules = new UVector(size, ec);
if (U_FAILURE(ec)) {
return NULL;
}
int32_t i;
for (i = 0; i < size; i++) {
rules->addElement(((TimeZoneRule*)source->elementAt(i))->clone(), ec);
if (U_FAILURE(ec)) {
break;
}
}
if (U_FAILURE(ec)) {
// In case of error, clean up
for (i = 0; i < rules->size(); i++) {
TimeZoneRule *rule = (TimeZoneRule*)rules->orphanElementAt(i);
delete rule;
}
delete rules;
return NULL;
}
return rules;
}
示例6: MetaZoneIDsEnumeration
StringEnumeration*
TimeZoneNamesImpl::getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const {
if (U_FAILURE(status)) {
return NULL;
}
const UVector* mappings = ZoneMeta::getMetazoneMappings(tzID);
if (mappings == NULL) {
return new MetaZoneIDsEnumeration();
}
MetaZoneIDsEnumeration *senum = NULL;
UVector* mzIDs = new UVector(NULL, uhash_compareUChars, status);
if (mzIDs == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_SUCCESS(status)) {
U_ASSERT(mzIDs != NULL);
for (int32_t i = 0; U_SUCCESS(status) && i < mappings->size(); i++) {
OlsonToMetaMappingEntry *map = (OlsonToMetaMappingEntry *)mappings->elementAt(i);
const UChar *mzID = map->mzid;
if (!mzIDs->contains((void *)mzID)) {
mzIDs->addElement((void *)mzID, status);
}
}
if (U_SUCCESS(status)) {
senum = new MetaZoneIDsEnumeration(mzIDs);
} else {
delete mzIDs;
}
}
return senum;
}
示例7: appendUnicodeSetToUVector
static void appendUnicodeSetToUVector(UVector &dest, const UnicodeSet &source, UErrorCode &status) {
UnicodeSetIterator setIter(source);
while (setIter.next()) {
const UnicodeString &str = setIter.getString();
dest.addElement(str.clone(), status);
}
}
示例8: UVector
UVector *AlphabeticIndex::firstStringsInScript(UErrorCode &status) {
if (U_FAILURE(status)) {
return NULL;
}
UVector *dest = new UVector(status);
if (dest == NULL) {
if (U_SUCCESS(status)) {
status = U_MEMORY_ALLOCATION_ERROR;
}
return NULL;
}
dest->setDeleter(uprv_deleteUObject);
const UChar *src = HACK_FIRST_CHARS_IN_SCRIPTS;
const UChar *limit = src + sizeof(HACK_FIRST_CHARS_IN_SCRIPTS) / sizeof(HACK_FIRST_CHARS_IN_SCRIPTS[0]);
do {
if (U_FAILURE(status)) {
return dest;
}
UnicodeString *str = new UnicodeString(src, -1);
if (str == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
} else {
dest->addElement(str, status);
src += str->length() + 1;
}
} while (src < limit);
dest->sortWithUComparator(sortCollateComparator, collator_, status);
return dest;
}
示例9: TestMultipleKeyStringFactory
TestMultipleKeyStringFactory(const UnicodeString ids[], int32_t count, const UnicodeString& factoryID)
: _status(U_ZERO_ERROR)
, _ids(uhash_deleteUnicodeString, uhash_compareUnicodeString, count, _status)
, _factoryID(factoryID + ": ")
{
for (int i = 0; i < count; ++i) {
_ids.addElement(new UnicodeString(ids[i]), _status);
}
}
示例10: UVector
UBool
GNameSearchHandler::handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (node->hasValues()) {
int32_t valuesCount = node->countValues();
for (int32_t i = 0; i < valuesCount; i++) {
GNameInfo *nameinfo = (ZNameInfo *)node->getValue(i);
if (nameinfo == NULL) {
break;
}
if ((nameinfo->type & fTypes) != 0) {
// matches a requested type
if (fResults == NULL) {
fResults = new UVector(uprv_free, NULL, status);
if (fResults == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
}
if (U_SUCCESS(status)) {
U_ASSERT(fResults != NULL);
GMatchInfo *gmatch = (GMatchInfo *)uprv_malloc(sizeof(GMatchInfo));
if (gmatch == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
} else {
// add the match to the vector
gmatch->gnameInfo = nameinfo;
gmatch->matchLength = matchLength;
gmatch->timeType = UTZFMT_TIME_TYPE_UNKNOWN;
fResults->addElement(gmatch, status);
if (U_FAILURE(status)) {
uprv_free(gmatch);
} else {
if (matchLength > fMaxMatchLen) {
fMaxMatchLen = matchLength;
}
}
}
}
}
}
}
return TRUE;
}
示例11: ServiceEnumeration
ServiceEnumeration(const ServiceEnumeration &other, UErrorCode &status)
: _service(other._service)
, _timestamp(other._timestamp)
, _ids(uhash_deleteUnicodeString, NULL, status)
, _pos(0)
{
if(U_SUCCESS(status)) {
int32_t i, length;
length = other._ids.size();
for(i = 0; i < length; ++i) {
_ids.addElement(((UnicodeString *)other._ids.elementAt(i))->clone(), status);
}
if(U_SUCCESS(status)) {
_pos = other._pos;
}
}
}
示例12: registerSTV
/**
* Register a source-target/variant in the specDAG. Variant may be
* empty, but source and target must not be. If variant is empty then
* the special variant NO_VARIANT is stored in slot zero of the
* UVector of variants.
*/
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) {
targets = new Hashtable(TRUE, status);
if (U_FAILURE(status) || targets == 0) {
return;
}
targets->setValueDeleter(uprv_deleteUObject);
specDAG.put(source, targets, status);
}
UVector *variants = (UVector*) targets->get(target);
if (variants == 0) {
variants = new UVector(uprv_deleteUObject,
uhash_compareCaselessUnicodeString, status);
if (variants == 0) {
return;
}
targets->put(target, variants, status);
}
// assert(NO_VARIANT == "");
// We add the variant string. If it is the special "no variant"
// string, that is, the empty string, we add it at position zero.
if (!variants->contains((void*) &variant)) {
UnicodeString *tempus; // Used for null pointer check.
if (variant.length() > 0) {
tempus = new UnicodeString(variant);
if (tempus != NULL) {
variants->addElement(tempus, status);
}
} else {
tempus = new UnicodeString(); // = NO_VARIANT
if (tempus != NULL) {
variants->insertElementAt(tempus, 0, status);
}
}
}
}
示例13: parseCompoundID
U_CDECL_END
/**
* Parse a compound ID, consisting of an optional forward global
* filter, a separator, one or more single IDs delimited by
* separators, an an optional reverse global filter. The
* separator is a semicolon. The global filters are UnicodeSet
* patterns. The reverse global filter must be enclosed in
* parentheses.
* @param id the pattern the parse
* @param dir the direction.
* @param canonID OUTPUT parameter that receives the canonical ID,
* consisting of canonical IDs for all elements, as returned by
* parseSingleID(), separated by semicolons. Previous contents
* are discarded.
* @param list OUTPUT parameter that receives a list of SingleID
* objects representing the parsed IDs. Previous contents are
* discarded.
* @param globalFilter OUTPUT parameter that receives a pointer to
* a newly created global filter for this ID in this direction, or
* NULL if there is none.
* @return TRUE if the parse succeeds, that is, if the entire
* id is consumed without syntax error.
*/
UBool TransliteratorIDParser::parseCompoundID(const UnicodeString & id, int32_t dir,
UnicodeString & canonID,
UVector & list,
UnicodeSet *& globalFilter)
{
UErrorCode ec = U_ZERO_ERROR;
int32_t i;
int32_t pos = 0;
int32_t withParens = 1;
list.removeAllElements();
UnicodeSet * filter;
globalFilter = NULL;
canonID.truncate(0);
// Parse leading global filter, if any
withParens = 0; // parens disallowed
filter = parseGlobalFilter(id, pos, dir, withParens, &canonID);
if (filter != NULL)
{
if (!ICU_Utility::parseChar(id, pos, ID_DELIM))
{
// Not a global filter; backup and resume
canonID.truncate(0);
pos = 0;
}
if (dir == FORWARD)
{
globalFilter = filter;
}
else
{
delete filter;
}
filter = NULL;
}
UBool sawDelimiter = TRUE;
for (;;)
{
SingleID * single = parseSingleID(id, pos, dir, ec);
if (single == NULL)
{
break;
}
if (dir == FORWARD)
{
list.addElement(single, ec);
}
else
{
list.insertElementAt(single, 0, ec);
}
if (U_FAILURE(ec))
{
goto FAIL;
}
if (!ICU_Utility::parseChar(id, pos, ID_DELIM))
{
sawDelimiter = FALSE;
break;
}
}
if (list.size() == 0)
{
goto FAIL;
}
// Construct canonical ID
for (i = 0; i < list.size(); ++i)
{
SingleID * single = (SingleID *) list.elementAt(i);
canonID.append(single->canonID);
if (i != (list.size() - 1))
{
canonID.append(ID_DELIM);
//.........这里部分代码省略.........
示例14: sizeof
UVector*
ZoneMeta::createMetazoneMappings(const UnicodeString &tzid) {
UVector *mzMappings = NULL;
UErrorCode status = U_ZERO_ERROR;
UnicodeString canonicalID;
UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
ures_getByKey(rb, gMetazoneInfo, rb, &status);
TimeZone::getCanonicalID(tzid, canonicalID, status);
if (U_SUCCESS(status)) {
char tzKey[ZID_KEY_MAX];
canonicalID.extract(0, canonicalID.length(), tzKey, sizeof(tzKey), US_INV);
// tzid keys are using ':' as separators
char *p = tzKey;
while (*p) {
if (*p == '/') {
*p = ':';
}
p++;
}
ures_getByKey(rb, tzKey, rb, &status);
if (U_SUCCESS(status)) {
UResourceBundle *mz = NULL;
while (ures_hasNext(rb)) {
mz = ures_getNextResource(rb, mz, &status);
const UChar *mz_name = ures_getStringByIndex(mz, 0, NULL, &status);
const UChar *mz_from = gDefaultFrom;
const UChar *mz_to = gDefaultTo;
if (ures_getSize(mz) == 3) {
mz_from = ures_getStringByIndex(mz, 1, NULL, &status);
mz_to = ures_getStringByIndex(mz, 2, NULL, &status);
}
if(U_FAILURE(status)){
status = U_ZERO_ERROR;
continue;
}
// We do not want to use SimpleDateformat to parse boundary dates,
// because this code could be triggered by the initialization code
// used by SimpleDateFormat.
UDate from = parseDate(mz_from, status);
UDate to = parseDate(mz_to, status);
if (U_FAILURE(status)) {
status = U_ZERO_ERROR;
continue;
}
OlsonToMetaMappingEntry *entry = (OlsonToMetaMappingEntry*)uprv_malloc(sizeof(OlsonToMetaMappingEntry));
if (entry == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
break;
}
entry->mzid = mz_name;
entry->from = from;
entry->to = to;
if (mzMappings == NULL) {
mzMappings = new UVector(deleteOlsonToMetaMappingEntry, NULL, status);
if (U_FAILURE(status)) {
delete mzMappings;
deleteOlsonToMetaMappingEntry(entry);
uprv_free(entry);
break;
}
}
mzMappings->addElement(entry, status);
if (U_FAILURE(status)) {
break;
}
}
ures_close(mz);
if (U_FAILURE(status)) {
if (mzMappings != NULL) {
delete mzMappings;
mzMappings = NULL;
}
}
}
}
ures_close(rb);
return mzMappings;
}
示例15: countTransitionRules
void
BasicTimeZone::getTimeZoneRulesAfter(UDate start, InitialTimeZoneRule*& initial,
UVector*& transitionRules, UErrorCode& status) /*const*/ {
if (U_FAILURE(status)) {
return;
}
const InitialTimeZoneRule *orgini;
const TimeZoneRule **orgtrs = NULL;
TimeZoneTransition tzt;
UBool avail;
UVector *orgRules = NULL;
int32_t ruleCount;
TimeZoneRule *r = NULL;
UBool *done = NULL;
InitialTimeZoneRule *res_initial = NULL;
UVector *filteredRules = NULL;
UnicodeString name;
int32_t i;
UDate time, t;
UDate *newTimes = NULL;
UDate firstStart;
UBool bFinalStd = FALSE, bFinalDst = FALSE;
// Original transition rules
ruleCount = countTransitionRules(status);
if (U_FAILURE(status)) {
return;
}
orgRules = new UVector(ruleCount, status);
if (U_FAILURE(status)) {
return;
}
orgtrs = (const TimeZoneRule**)uprv_malloc(sizeof(TimeZoneRule*)*ruleCount);
if (orgtrs == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
goto error;
}
getTimeZoneRules(orgini, orgtrs, ruleCount, status);
if (U_FAILURE(status)) {
goto error;
}
for (i = 0; i < ruleCount; i++) {
orgRules->addElement(orgtrs[i]->clone(), status);
if (U_FAILURE(status)) {
goto error;
}
}
uprv_free(orgtrs);
orgtrs = NULL;
avail = getPreviousTransition(start, TRUE, tzt);
if (!avail) {
// No need to filter out rules only applicable to time before the start
initial = orgini->clone();
transitionRules = orgRules;
return;
}
done = (UBool*)uprv_malloc(sizeof(UBool)*ruleCount);
if (done == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
goto error;
}
filteredRules = new UVector(status);
if (U_FAILURE(status)) {
goto error;
}
// Create initial rule
tzt.getTo()->getName(name);
res_initial = new InitialTimeZoneRule(name, tzt.getTo()->getRawOffset(),
tzt.getTo()->getDSTSavings());
// Mark rules which does not need to be processed
for (i = 0; i < ruleCount; i++) {
r = (TimeZoneRule*)orgRules->elementAt(i);
avail = r->getNextStart(start, res_initial->getRawOffset(), res_initial->getDSTSavings(), FALSE, time);
done[i] = !avail;
}
time = start;
while (!bFinalStd || !bFinalDst) {
avail = getNextTransition(time, FALSE, tzt);
if (!avail) {
break;
}
UDate updatedTime = tzt.getTime();
if (updatedTime == time) {
// Can get here if rules for start & end of daylight time have exactly
// the same time.
// TODO: fix getNextTransition() to prevent it?
status = U_INVALID_STATE_ERROR;
goto error;
}
time = updatedTime;
const TimeZoneRule *toRule = tzt.getTo();
for (i = 0; i < ruleCount; i++) {
r = (TimeZoneRule*)orgRules->elementAt(i);
//.........这里部分代码省略.........