本文整理汇总了C++中UnicodeString::setTo方法的典型用法代码示例。如果您正苦于以下问题:C++ UnicodeString::setTo方法的具体用法?C++ UnicodeString::setTo怎么用?C++ UnicodeString::setTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnicodeString
的用法示例。
在下文中一共展示了UnicodeString::setTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verifyIsRelativeDateFormat
U_CAPI int32_t U_EXPORT2
udat_toPatternRelativeTime(const UDateFormat *fmt,
UChar *result,
int32_t resultLength,
UErrorCode *status)
{
verifyIsRelativeDateFormat(fmt, status);
if(U_FAILURE(*status)) return -1;
UnicodeString timePattern;
if(!(result==NULL && resultLength==0)) {
// NULL destination for pure preflighting: empty dummy string
// otherwise, alias the destination buffer
timePattern.setTo(result, 0, resultLength);
}
((RelativeDateFormat*)fmt)->toPatternTime(timePattern, *status);
return timePattern.extract(result, resultLength, *status);
}
示例2: getRules
void RuleBasedCollator::getRules(UColRuleOption delta, UnicodeString &buffer)
{
int32_t rulesize = ucol_getRulesEx(ucollator, delta, NULL, -1);
if (rulesize > 0) {
UChar *rules = (UChar*) uprv_malloc( sizeof(UChar) * (rulesize) );
if(rules != NULL) {
ucol_getRulesEx(ucollator, delta, rules, rulesize);
buffer.setTo(rules, rulesize);
uprv_free(rules);
} else { // couldn't allocate
buffer.remove();
}
}
else {
buffer.remove();
}
}
示例3: UnicodeString
UnicodeString& U_EXPORT2
TimeZoneNamesImpl::getDefaultExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) {
if (tzID.isEmpty() || tzID.startsWith(gEtcPrefix, gEtcPrefixLen)
|| tzID.startsWith(gSystemVPrefix, gSystemVPrefixLen) || tzID.indexOf(gRiyadh8, gRiyadh8Len, 0) > 0) {
name.setToBogus();
return name;
}
int32_t sep = tzID.lastIndexOf((UChar)0x2F /* '/' */);
if (sep > 0 && sep + 1 < tzID.length()) {
name.setTo(tzID, sep + 1);
name.findAndReplace(UnicodeString((UChar)0x5f /* _ */),
UnicodeString((UChar)0x20 /* space */));
} else {
name.setToBogus();
}
return name;
}
示例4:
U_NAMESPACE_USE
static TimeZone*
_createTimeZone(const UChar* zoneID, int32_t len, UErrorCode* ec) {
TimeZone* zone = NULL;
if (ec!=NULL && U_SUCCESS(*ec)) {
// Note that if zoneID is invalid, we get back GMT. This odd
// behavior is by design and goes back to the JDK. The only
// failure we will see is a memory allocation failure.
int32_t l = (len<0 ? u_strlen(zoneID) : len);
UnicodeString zoneStrID;
zoneStrID.setTo((UBool)(len < 0), zoneID, l); /* temporary read-only alias */
zone = TimeZone::createTimeZone(zoneStrID);
if (zone == NULL) {
*ec = U_MEMORY_ALLOCATION_ERROR;
}
}
return zone;
}
示例5: getMetazoneMappings
UnicodeString& U_EXPORT2
ZoneMeta::getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result) {
UBool isSet = FALSE;
const UVector *mappings = getMetazoneMappings(tzid);
if (mappings != NULL) {
for (int32_t i = 0; i < mappings->size(); i++) {
OlsonToMetaMappingEntry *mzm = (OlsonToMetaMappingEntry*)mappings->elementAt(i);
if (mzm->from <= date && mzm->to > date) {
result.setTo(mzm->mzid, -1);
isSet = TRUE;
break;
}
}
}
if (!isSet) {
result.remove();
}
return result;
}
示例6:
UnicodeString& U_EXPORT2
ZoneMeta::getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString ®ion, UnicodeString &result) {
UErrorCode status = U_ZERO_ERROR;
const UChar *tzid = NULL;
int32_t tzidLen = 0;
char keyBuf[ZID_KEY_MAX + 1];
int32_t keyLen = 0;
if (mzid.length() >= ZID_KEY_MAX) {
result.remove();
return result;
}
keyLen = mzid.extract(0, mzid.length(), keyBuf, ZID_KEY_MAX, US_INV);
UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
ures_getByKey(rb, gMapTimezonesTag, rb, &status);
ures_getByKey(rb, keyBuf, rb, &status);
if (U_SUCCESS(status)) {
// check region mapping
if (region.length() == 2 || region.length() == 3) {
region.extract(0, region.length(), keyBuf, ZID_KEY_MAX, US_INV);
tzid = ures_getStringByKey(rb, keyBuf, &tzidLen, &status);
if (status == U_MISSING_RESOURCE_ERROR) {
status = U_ZERO_ERROR;
}
}
if (U_SUCCESS(status) && tzid == NULL) {
// try "001"
tzid = ures_getStringByKey(rb, gWorldTag, &tzidLen, &status);
}
}
ures_close(rb);
if (tzid == NULL) {
result.remove();
} else {
result.setTo(tzid, tzidLen);
}
return result;
}
示例7: IDtoSTV
/**
* Parse an ID into pieces. Take IDs of the form T, T/V, S-T,
* S-T/V, or S/V-T. If the source is missing, return a source of
* ANY.
* @param id the id string, in any of several forms
* @return an array of 4 strings: source, target, variant, and
* isSourcePresent. If the source is not present, ANY will be
* given as the source, and isSourcePresent will be NULL. Otherwise
* isSourcePresent will be non-NULL. The target may be empty if the
* id is not well-formed. The variant may be empty.
*/
void TransliteratorIDParser::IDtoSTV(const UnicodeString& id,
UnicodeString& source,
UnicodeString& target,
UnicodeString& variant,
UBool& isSourcePresent) {
source.setTo(ANY, 3);
target.truncate(0);
variant.truncate(0);
int32_t sep = id.indexOf(TARGET_SEP);
int32_t var = id.indexOf(VARIANT_SEP);
if (var < 0) {
var = id.length();
}
isSourcePresent = FALSE;
if (sep < 0) {
// Form: T/V or T (or /V)
id.extractBetween(0, var, target);
id.extractBetween(var, id.length(), variant);
} else if (sep < var) {
// Form: S-T/V or S-T (or -T/V or -T)
if (sep > 0) {
id.extractBetween(0, sep, source);
isSourcePresent = TRUE;
}
id.extractBetween(++sep, var, target);
id.extractBetween(var, id.length(), variant);
} else {
// Form: (S/V-T or /V-T)
if (var > 0) {
id.extractBetween(0, var, source);
isSourcePresent = TRUE;
}
id.extractBetween(var, sep++, variant);
id.extractBetween(sep, id.length(), target);
}
if (variant.length() > 0) {
variant.remove(0, 1);
}
}
示例8: PyUnicode_FromUnicodeString
static PyObject *t_canonicaliterator_getSource(t_canonicaliterator *self,
PyObject *args)
{
UnicodeString *u;
UnicodeString _u;
switch (PyTuple_Size(args)) {
case 0:
_u = self->object->getSource();
return PyUnicode_FromUnicodeString(&_u);
case 1:
if (!parseArgs(args, "U", &u))
{
u->setTo(self->object->getSource());
Py_RETURN_ARG(args, 0);
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "getSource", args);
}
示例9: PyUnicode_FromUnicodeString
static PyObject *t_resourcebundle_getNextString(t_resourcebundle *self,
PyObject *args)
{
UnicodeString *u;
UnicodeString _u;
switch (PyTuple_Size(args)) {
case 0:
STATUS_CALL(_u = self->object->getNextString(status));
return PyUnicode_FromUnicodeString(&_u);
case 1:
if (!parseArgs(args, "U", &u))
{
STATUS_CALL(u->setTo(self->object->getNextString(status)));
Py_RETURN_ARG(args, 0);
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "getNextString", args);
}
示例10: 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;
}
示例11: numSP
U_CAPI int32_t U_EXPORT2
unum_formatDecimal(const UNumberFormat* fmt,
const char * number,
int32_t length,
UChar* result,
int32_t resultLength,
UFieldPosition *pos, /* 0 if ignore */
UErrorCode* status) {
if(U_FAILURE(*status)) {
return -1;
}
if ((result == NULL && resultLength != 0) || resultLength < 0) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return -1;
}
FieldPosition fp;
if(pos != 0) {
fp.setField(pos->field);
}
if (length < 0) {
length = uprv_strlen(number);
}
StringPiece numSP(number, length);
Formattable numFmtbl(numSP, *status);
UnicodeString resultStr;
if (resultLength > 0) {
// Alias the destination buffer.
resultStr.setTo(result, 0, resultLength);
}
((const NumberFormat*)fmt)->format(numFmtbl, resultStr, fp, *status);
if(pos != 0) {
pos->beginIndex = fp.getBeginIndex();
pos->endIndex = fp.getEndIndex();
}
return resultStr.extract(result, resultLength, *status);
}
示例12: switch
U_CAPI int32_t U_EXPORT2
ucal_getTimeZoneDisplayName(const UCalendar* cal,
UCalendarDisplayNameType type,
const char *locale,
UChar* result,
int32_t resultLength,
UErrorCode* status)
{
if(U_FAILURE(*status)) return -1;
const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
UnicodeString id;
if(!(result==NULL && resultLength==0)) {
// NULL destination for pure preflighting: empty dummy string
// otherwise, alias the destination buffer
id.setTo(result, 0, resultLength);
}
switch(type) {
case UCAL_STANDARD:
tz.getDisplayName(FALSE, TimeZone::LONG, Locale(locale), id);
break;
case UCAL_SHORT_STANDARD:
tz.getDisplayName(FALSE, TimeZone::SHORT, Locale(locale), id);
break;
case UCAL_DST:
tz.getDisplayName(TRUE, TimeZone::LONG, Locale(locale), id);
break;
case UCAL_SHORT_DST:
tz.getDisplayName(TRUE, TimeZone::SHORT, Locale(locale), id);
break;
}
return id.extract(result, resultLength, *status);
}
示例13: if
U_CAPI int32_t U_EXPORT2
udat_toPattern( const UDateFormat *fmt,
UBool localized,
UChar *result,
int32_t resultLength,
UErrorCode *status)
{
if(U_FAILURE(*status)) {
return -1;
}
if (result == NULL ? resultLength != 0 : resultLength < 0) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return -1;
}
UnicodeString res;
if (result != NULL) {
// NULL destination for pure preflighting: empty dummy string
// otherwise, alias the destination buffer
res.setTo(result, 0, resultLength);
}
const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt);
const SimpleDateFormat *sdtfmt=dynamic_cast<const SimpleDateFormat *>(df);
const RelativeDateFormat *reldtfmt;
if (sdtfmt!=NULL) {
if(localized)
sdtfmt->toLocalizedPattern(res, *status);
else
sdtfmt->toPattern(res);
} else if (!localized && (reldtfmt=dynamic_cast<const RelativeDateFormat *>(df))!=NULL) {
reldtfmt->toPattern(res, *status);
} else {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return -1;
}
return res.extract(result, resultLength, *status);
}
示例14: if
void
RuleBasedNumberFormat::stripWhitespace(UnicodeString& description)
{
// iterate through the characters...
UnicodeString result;
int start = 0;
while (start != -1 && start < description.length()) {
// seek to the first non-whitespace character...
while (start < description.length()
&& PatternProps::isWhiteSpace(description.charAt(start))) {
++start;
}
// locate the next semicolon in the text and copy the text from
// our current position up to that semicolon into the result
int32_t p = description.indexOf(gSemiColon, start);
if (p == -1) {
// or if we don't find a semicolon, just copy the rest of
// the string into the result
result.append(description, start, description.length() - start);
start = -1;
}
else if (p < description.length()) {
result.append(description, start, p + 1 - start);
start = p + 1;
}
// when we get here, we've seeked off the end of the sring, and
// we terminate the loop (we continue until *start* is -1 rather
// than until *p* is -1, because otherwise we'd miss the last
// rule in the description)
else {
start = -1;
}
}
description.setTo(result);
}
示例15:
NumberingSystem* U_EXPORT2
NumberingSystem::createInstanceByName(const char *name, UErrorCode& status) {
UResourceBundle *numberingSystemsInfo = NULL;
UResourceBundle *nsTop, *nsCurrent;
const UChar* description = NULL;
int32_t radix = 10;
int32_t algorithmic = 0;
int32_t len;
numberingSystemsInfo = ures_openDirect(NULL,gNumberingSystems, &status);
nsCurrent = ures_getByKey(numberingSystemsInfo,gNumberingSystems,NULL,&status);
nsTop = ures_getByKey(nsCurrent,name,NULL,&status);
description = ures_getStringByKey(nsTop,gDesc,&len,&status);
ures_getByKey(nsTop,gRadix,nsCurrent,&status);
radix = ures_getInt(nsCurrent,&status);
ures_getByKey(nsTop,gAlgorithmic,nsCurrent,&status);
algorithmic = ures_getInt(nsCurrent,&status);
UBool isAlgorithmic = ( algorithmic == 1 );
UnicodeString nsd;
nsd.setTo(description);
ures_close(nsCurrent);
ures_close(nsTop);
ures_close(numberingSystemsInfo);
if (U_FAILURE(status)) {
status = U_UNSUPPORTED_ERROR;
return NULL;
}
NumberingSystem* ns = NumberingSystem::createInstance(radix,isAlgorithmic,nsd,status);
ns->setName(name);
return ns;
}