本文整理汇总了C++中CharString::append方法的典型用法代码示例。如果您正苦于以下问题:C++ CharString::append方法的具体用法?C++ CharString::append怎么用?C++ CharString::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharString
的用法示例。
在下文中一共展示了CharString::append方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
CharString operator+(const CharString& str1, const CharString& str2){
CharString str;
for(int i=0; i<str1.length(); i++){
str.append(str1[i]);
}
for(int i=0; i<str2.length(); i++){
str.append(str2[i]);
}
return str;
}
示例2: loadNumericDateFormatterPattern
static UnicodeString loadNumericDateFormatterPattern(
const UResourceBundle *resource,
const char *pattern,
UErrorCode &status) {
UnicodeString result;
if (U_FAILURE(status)) {
return result;
}
CharString chs;
chs.append("durationUnits", status)
.append("/", status).append(pattern, status);
LocalUResourceBundlePointer patternBundle(
ures_getByKeyWithFallback(
resource,
chs.data(),
NULL,
&status));
if (U_FAILURE(status)) {
return result;
}
getString(patternBundle.getAlias(), result, status);
// Replace 'h' with 'H'
int32_t len = result.length();
UChar *buffer = result.getBuffer(len);
for (int32_t i = 0; i < len; ++i) {
if (buffer[i] == 0x68) { // 'h'
buffer[i] = 0x48; // 'H'
}
}
result.releaseBuffer(len);
return result;
}
示例3: transform
void transform(const UnicodeString &word, CharString &buf, UErrorCode &errorCode) {
UChar32 c = 0;
int32_t len = word.length();
for (int32_t i = 0; i < len; i += U16_LENGTH(c)) {
c = word.char32At(i);
buf.append(transform(c, errorCode), errorCode);
}
}
示例4: load
static void load(const Locale& inLocale, CDFLocaleData* result, UErrorCode& status) {
LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(inLocale, status));
if (U_FAILURE(status)) {
return;
}
const char* nsName = ns->getName();
LocalUResourceBundlePointer resource(ures_open(NULL, inLocale.getName(), &status));
if (U_FAILURE(status)) {
return;
}
CmptDecDataSink sink(*result);
sink.isFallback = FALSE;
// First load the number elements data if nsName is not Latin.
if (uprv_strcmp(nsName, gLatnTag) != 0) {
sink.isLatin = FALSE;
CharString path;
path.append(gNumberElementsTag, status)
.append('/', status)
.append(nsName, status);
ures_getAllItemsWithFallback(resource.getAlias(), path.data(), sink, status);
if (status == U_MISSING_RESOURCE_ERROR) {
// Silently ignore and use Latin
status = U_ZERO_ERROR;
} else if (U_FAILURE(status)) {
return;
}
sink.isFallback = TRUE;
}
// Now load Latin.
sink.isLatin = TRUE;
ures_getAllItemsWithFallback(resource.getAlias(), gLatnPath, sink, status);
if (U_FAILURE(status)) return;
// If longData is empty, default it to be equal to shortData
if (result->longData.isEmpty()) {
result->longData.setToBogus();
}
// Check for "other" variants in each of the three data classes, and resolve missing elements.
if (!result->longData.isBogus()) {
checkForOtherVariants(&result->longData, status);
if (U_FAILURE(status)) return;
fillInMissing(&result->longData);
}
checkForOtherVariants(&result->shortData, status);
if (U_FAILURE(status)) return;
fillInMissing(&result->shortData);
// TODO: Enable this statement when currency support is added
// checkForOtherVariants(&result->shortCurrencyData, status);
// if (U_FAILURE(status)) return;
// fillInMissing(&result->shortCurrencyData);
}
示例5: subString
CharString CharString::subString(int start, int end) const{
if(end==-1 || end>length())
end = length();
if(start<0)
start = 0;
CharString str;
for(int i=start; i<end; i++){
str.append(operator[](i));
}
return str;
}
示例6: thaiWordToBytes
static UBool thaiWordToBytes(const UChar *s, int32_t length,
CharString &str, UErrorCode &errorCode) {
for(int32_t i=0; i<length; ++i) {
UChar c=s[i];
int32_t b=thaiCharToByte(c);
if(b>=0) {
str.append((char)b, errorCode);
} else {
fprintf(stderr, "thaiWordToBytes(): unable to encode U+%04X as a byte\n", c);
return FALSE;
}
}
return TRUE;
}
示例7: getDecimal
/**
* Return a string form of this number.
* Format is as defined by the decNumber library, for interchange of
* decimal numbers.
*/
void DigitList::getDecimal(CharString &str, UErrorCode &status) {
if (U_FAILURE(status)) {
return;
}
// A decimal number in string form can, worst case, be 14 characters longer
// than the number of digits. So says the decNumber library doc.
int32_t maxLength = fDecNumber->digits + 14;
int32_t capacity = 0;
char *buffer = str.clear().getAppendBuffer(maxLength, 0, capacity, status);
if (U_FAILURE(status)) {
return; // Memory allocation error on growing the string.
}
U_ASSERT(capacity >= maxLength);
uprv_decNumberToString(this->fDecNumber, buffer);
U_ASSERT((int32_t)uprv_strlen(buffer) <= maxLength);
str.append(buffer, -1, status);
}
示例8: parseName
void
NamesPropsBuilder::setProps(const UniProps &props, const UnicodeSet &newValues,
UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) { return; }
if(!newValues.contains(UCHAR_NAME) && !newValues.contains(PPUCD_NAME_ALIAS)) {
return;
}
U_ASSERT(props.start==props.end);
const char *names[4]={ NULL, NULL, NULL, NULL };
int16_t lengths[4]={ 0, 0, 0, 0 };
/* get the character name */
if(props.name!=NULL) {
names[0]=props.name;
lengths[0]=(int16_t)uprv_strlen(props.name);
parseName(names[0], lengths[0]);
}
CharString buffer;
if(props.nameAlias!=NULL) {
/*
* Only use "correction" aliases for now, from Unicode 6.1 NameAliases.txt with 3 fields per line.
* TODO: Work on ticket #8963 to deal with multiple type:alias pairs per character.
*/
const char *corr=uprv_strstr(props.nameAlias, "correction=");
if(corr!=NULL) {
corr+=11; // skip "correction="
const char *limit=uprv_strchr(corr, ',');
if(limit!=NULL) {
buffer.append(corr, limit-corr, errorCode);
names[3]=buffer.data();
lengths[3]=(int16_t)(limit-corr);
} else {
names[3]=corr;
lengths[3]=(int16_t)uprv_strlen(corr);
}
parseName(names[3], lengths[3]);
}
}
addLine(props.start, names, lengths, LENGTHOF(names));
}
示例9:
void
DigitList::appendDigitsTo(CharString &str, UErrorCode &status) const {
str.append((const char *) fDecNumber->lsu, fDecNumber->digits, status);
}
示例10: StringResource
//.........这里部分代码省略.........
if(options[WRITE_POOL_BUNDLE].doesOccur) {
newPoolBundle.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL, TRUE, status), status);
if(U_FAILURE(status)) {
fprintf(stderr, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status));
return status;
} else {
const char *poolResName = "pool.res";
char *nameWithoutSuffix = static_cast<char *>(uprv_malloc(uprv_strlen(poolResName) + 1));
if (nameWithoutSuffix == NULL) {
fprintf(stderr, "out of memory error\n");
return U_MEMORY_ALLOCATION_ERROR;
}
uprv_strcpy(nameWithoutSuffix, poolResName);
*uprv_strrchr(nameWithoutSuffix, '.') = 0;
newPoolBundle->fLocale = nameWithoutSuffix;
}
}
if(options[USE_POOL_BUNDLE].doesOccur) {
const char *poolResName = "pool.res";
FileStream *poolFile;
int32_t poolFileSize;
int32_t indexLength;
/*
* TODO: Consolidate inputDir/filename handling from main() and processFile()
* into a common function, and use it here as well.
* Try to create toolutil functions for dealing with dir/filenames and
* loading ICU data files without udata_open().
* Share code with icupkg?
* Also, make_res_filename() seems to be unused. Review and remove.
*/
CharString poolFileName;
if (options[USE_POOL_BUNDLE].value!=NULL) {
poolFileName.append(options[USE_POOL_BUNDLE].value, status);
} else if (inputDir) {
poolFileName.append(inputDir, status);
}
poolFileName.appendPathPart(poolResName, status);
if (U_FAILURE(status)) {
return status;
}
poolFile = T_FileStream_open(poolFileName.data(), "rb");
if (poolFile == NULL) {
fprintf(stderr, "unable to open pool bundle file %s\n", poolFileName.data());
return 1;
}
poolFileSize = T_FileStream_size(poolFile);
if (poolFileSize < 32) {
fprintf(stderr, "the pool bundle file %s is too small\n", poolFileName.data());
return 1;
}
poolBundle.fBytes = new uint8_t[(poolFileSize + 15) & ~15];
if (poolFileSize > 0 && poolBundle.fBytes == NULL) {
fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", poolFileName.data());
return U_MEMORY_ALLOCATION_ERROR;
}
UDataSwapper *ds;
const DataHeader *header;
int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize);
if (bytesRead != poolFileSize) {
fprintf(stderr, "unable to read the pool bundle file %s\n", poolFileName.data());
return 1;
}
/*
* Swap the pool bundle so that a single checked-in file can be used.
示例11: digitString
void
DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool useLastResortData)
{
if (U_FAILURE(status)) { return; }
*validLocale = *actualLocale = 0;
currPattern = NULL;
// First initialize all the symbols to the fallbacks for anything we can't find
initialize();
//
// Next get the numbering system for this locale and set zero digit
// and the digit string based on the numbering system for the locale
//
LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(loc, status));
const char *nsName;
if (U_SUCCESS(status) && ns->getRadix() == 10 && !ns->isAlgorithmic()) {
nsName = ns->getName();
UnicodeString digitString(ns->getDescription());
int32_t digitIndex = 0;
UChar32 digit = digitString.char32At(0);
fSymbols[kZeroDigitSymbol].setTo(digit);
for (int32_t i = kOneDigitSymbol; i <= kNineDigitSymbol; ++i) {
digitIndex += U16_LENGTH(digit);
digit = digitString.char32At(digitIndex);
fSymbols[i].setTo(digit);
}
} else {
nsName = gLatn;
}
// Open resource bundles
const char* locStr = loc.getName();
LocalUResourceBundlePointer resource(ures_open(NULL, locStr, &status));
LocalUResourceBundlePointer numberElementsRes(
ures_getByKeyWithFallback(resource.getAlias(), gNumberElements, NULL, &status));
if (U_FAILURE(status)) {
if ( useLastResortData ) {
status = U_USING_DEFAULT_WARNING;
initialize();
}
return;
}
// Set locale IDs
// TODO: Is there a way to do this without depending on the resource bundle instance?
U_LOCALE_BASED(locBased, *this);
locBased.setLocaleIDs(
ures_getLocaleByType(
numberElementsRes.getAlias(),
ULOC_VALID_LOCALE, &status),
ures_getLocaleByType(
numberElementsRes.getAlias(),
ULOC_ACTUAL_LOCALE, &status));
// Now load the rest of the data from the data sink.
// Start with loading this nsName if it is not Latin.
DecFmtSymDataSink sink(*this);
if (uprv_strcmp(nsName, gLatn) != 0) {
CharString path;
path.append(gNumberElements, status)
.append('/', status)
.append(nsName, status)
.append('/', status)
.append(gSymbols, status);
ures_getAllItemsWithFallback(resource.getAlias(), path.data(), sink, status);
// If no symbols exist for the given nsName and resource bundle, silently ignore
// and fall back to Latin.
if (status == U_MISSING_RESOURCE_ERROR) {
status = U_ZERO_ERROR;
} else if (U_FAILURE(status)) {
return;
}
}
// Continue with Latin if necessary.
if (!sink.seenAll()) {
ures_getAllItemsWithFallback(resource.getAlias(), gNumberElementsLatnSymbols, sink, status);
if (U_FAILURE(status)) { return; }
}
// Let the monetary number separators equal the default number separators if necessary.
sink.resolveMissingMonetarySeparators(fSymbols);
// Obtain currency data from the currency API. This is strictly
// for backward compatibility; we don't use DecimalFormatSymbols
// for currency data anymore.
UErrorCode internalStatus = U_ZERO_ERROR; // don't propagate failures out
UChar curriso[4];
UnicodeString tempStr;
ucurr_forLocale(locStr, curriso, 4, &internalStatus);
uprv_getStaticCurrencyName(curriso, locStr, tempStr, internalStatus);
if (U_SUCCESS(internalStatus)) {
fSymbols[kIntlCurrencySymbol].setTo(curriso, -1);
fSymbols[kCurrencySymbol] = tempStr;
}
/* else use the default values. */
//.........这里部分代码省略.........
示例12: sizeof
void
NamesPropsBuilder::setAlgNamesRange(UChar32 start, UChar32 end,
const char *type,
const char *prefix, // number of hex digits
UErrorCode &errorCode) {
/* modulo factors, maximum 8 */
/* 3 factors: 19, 21, 28, most-to-least-significant */
static const uint16_t hangulFactors[3]={
19, 21, 28
};
static const char jamo[]=
"HANGUL SYLLABLE \0"
"G\0GG\0N\0D\0DD\0R\0M\0B\0BB\0"
"S\0SS\0\0J\0JJ\0C\0K\0T\0P\0H\0"
"A\0AE\0YA\0YAE\0EO\0E\0YEO\0YE\0O\0"
"WA\0WAE\0OE\0YO\0U\0WEO\0WE\0WI\0"
"YU\0EU\0YI\0I\0"
"\0G\0GG\0GS\0N\0NJ\0NH\0D\0L\0LG\0LM\0"
"LB\0LS\0LT\0LP\0LH\0M\0B\0BS\0"
"S\0SS\0NG\0J\0C\0K\0T\0P\0H";
int32_t prefixLength=0;
AlgorithmicRange range;
uprv_memset(&range, 0, sizeof(AlgorithmicRange));
int32_t rangeSize=(int32_t)sizeof(AlgorithmicRange);
range.start=start;
range.end=end;
if(0==uprv_strcmp(type, "han")) {
range.type=0;
range.variant= end<=0xffff ? 4 : 5;
prefixLength=uprv_strlen(prefix)+1;
rangeSize+=prefixLength;
} else if(0==uprv_strcmp(type, "hangul")) {
range.type=1;
range.variant=(uint8_t)LENGTHOF(hangulFactors);
rangeSize+=(int32_t)sizeof(hangulFactors);
rangeSize+=(int32_t)sizeof(jamo);
} else {
fprintf(stderr, "genprops error: unknown algnamesrange type '%s'\n", prefix);
errorCode=U_ILLEGAL_ARGUMENT_ERROR;
return;
}
int32_t paddingLength=paddingLength=rangeSize&3;
if(paddingLength) {
paddingLength=4-paddingLength;
rangeSize+=paddingLength;
}
range.size=(uint16_t)rangeSize;
algRanges.append((char *)&range, (int32_t)sizeof(AlgorithmicRange), errorCode);
if(range.type==0) { // han
algRanges.append(prefix, prefixLength, errorCode);
} else /* type==1 */ { // hangul
algRanges.append((char *)hangulFactors, (int32_t)sizeof(hangulFactors), errorCode);
algRanges.append(jamo, (int32_t)sizeof(jamo), errorCode);
}
while(paddingLength) {
algRanges.append((char)0xaa, errorCode);
--paddingLength;
}
++countAlgRanges;
}
示例13: fprintf
// Returns TRUE for "ok to continue parsing fields".
UBool
PreparsedUCD::parseProperty(UniProps &props, const char *field, UnicodeSet &newValues,
UErrorCode &errorCode) {
CharString pBuffer;
const char *p=field;
const char *v=strchr(p, '=');
int binaryValue;
if(*p=='-') {
if(v!=NULL) {
fprintf(stderr,
"error in preparsed UCD: mix of binary-property-no and "
"enum-property syntax '%s' on line %ld\n",
field, (long)lineNumber);
errorCode=U_PARSE_ERROR;
return FALSE;
}
binaryValue=0;
++p;
} else if(v==NULL) {
binaryValue=1;
} else {
binaryValue=-1;
// Copy out the property name rather than modifying the field (writing a NUL).
pBuffer.append(p, (int32_t)(v-p), errorCode);
p=pBuffer.data();
++v;
}
int32_t prop=pnames->getPropertyEnum(p);
if(prop<0) {
for(int32_t i=0;; ++i) {
if(i==UPRV_LENGTHOF(ppucdProperties)) {
// Ignore unknown property names.
return TRUE;
}
if(0==uprv_stricmp(p, ppucdProperties[i].name)) {
prop=ppucdProperties[i].prop;
U_ASSERT(prop>=0);
break;
}
}
}
if(prop<UCHAR_BINARY_LIMIT) {
if(binaryValue>=0) {
props.binProps[prop]=(UBool)binaryValue;
} else {
// No binary value for a binary property.
fprintf(stderr,
"error in preparsed UCD: enum-property syntax '%s' "
"for binary property on line %ld\n",
field, (long)lineNumber);
errorCode=U_PARSE_ERROR;
}
} else if(binaryValue>=0) {
// Binary value for a non-binary property.
fprintf(stderr,
"error in preparsed UCD: binary-property syntax '%s' "
"for non-binary property on line %ld\n",
field, (long)lineNumber);
errorCode=U_PARSE_ERROR;
} else if (prop < UCHAR_INT_START) {
fprintf(stderr,
"error in preparsed UCD: prop value is invalid: '%d' for line %ld\n",
prop, (long)lineNumber);
errorCode=U_PARSE_ERROR;
} else if(prop<UCHAR_INT_LIMIT) {
int32_t value=pnames->getPropertyValueEnum(prop, v);
if(value==UCHAR_INVALID_CODE && prop==UCHAR_CANONICAL_COMBINING_CLASS) {
// TODO: Make getPropertyValueEnum(UCHAR_CANONICAL_COMBINING_CLASS, v) work.
char *end;
unsigned long ccc=uprv_strtoul(v, &end, 10);
if(v<end && *end==0 && ccc<=254) {
value=(int32_t)ccc;
}
}
if(value==UCHAR_INVALID_CODE) {
fprintf(stderr,
"error in preparsed UCD: '%s' is not a valid value on line %ld\n",
field, (long)lineNumber);
errorCode=U_PARSE_ERROR;
} else {
props.intProps[prop-UCHAR_INT_START]=value;
}
} else if(*v=='<') {
// Do not parse default values like <code point>, just set null values.
switch(prop) {
case UCHAR_BIDI_MIRRORING_GLYPH:
props.bmg=U_SENTINEL;
break;
case UCHAR_BIDI_PAIRED_BRACKET:
props.bpb=U_SENTINEL;
break;
case UCHAR_SIMPLE_CASE_FOLDING:
props.scf=U_SENTINEL;
break;
case UCHAR_SIMPLE_LOWERCASE_MAPPING:
props.slc=U_SENTINEL;
break;
case UCHAR_SIMPLE_TITLECASE_MAPPING:
props.stc=U_SENTINEL;
//.........这里部分代码省略.........
示例14: uplug_getPluginFile
U_CAPI void U_EXPORT2
uplug_init(UErrorCode *status) {
#if !U_ENABLE_DYLOAD
(void)status; /* unused */
#elif !UCONFIG_NO_FILE_IO
CharString plugin_dir;
const char *env = getenv("ICU_PLUGINS");
if(U_FAILURE(*status)) return;
if(env != NULL) {
plugin_dir.append(env, -1, *status);
}
if(U_FAILURE(*status)) return;
#if defined(DEFAULT_ICU_PLUGINS)
if(plugin_dir.isEmpty()) {
plugin_dir.append(DEFAULT_ICU_PLUGINS, -1, *status);
}
#endif
#if UPLUG_TRACE
DBG((stderr, "ICU_PLUGINS=%s\n", plugin_dir.data()));
#endif
if(!plugin_dir.isEmpty()) {
FILE *f;
CharString pluginFile;
#ifdef OS390BATCH
/* There are potentially a lot of ways to implement a plugin directory on OS390/zOS */
/* Keeping in mind that unauthorized file access is logged, monitored, and enforced */
/* I've chosen to open a DDNAME if BATCH and leave it alone for (presumably) UNIX */
/* System Services. Alternative techniques might be allocating a member in */
/* SYS1.PARMLIB or setting an environment variable "ICU_PLUGIN_PATH" (?). The */
/* DDNAME can be connected to a file in the HFS if need be. */
pluginFile.append("//DD:ICUPLUG", -1, *status); /* JAM 20 Oct 2011 */
#else
pluginFile.append(plugin_dir, *status);
pluginFile.append(U_FILE_SEP_STRING, -1, *status);
pluginFile.append("icuplugins", -1, *status);
pluginFile.append(U_ICU_VERSION_SHORT, -1, *status);
pluginFile.append(".txt", -1, *status);
#endif
#if UPLUG_TRACE
DBG((stderr, "status=%s\n", u_errorName(*status)));
#endif
if(U_FAILURE(*status)) {
return;
}
if((size_t)pluginFile.length() > (sizeof(plugin_file)-1)) {
*status = U_BUFFER_OVERFLOW_ERROR;
#if UPLUG_TRACE
DBG((stderr, "status=%s\n", u_errorName(*status)));
#endif
return;
}
/* plugin_file is not used for processing - it is only used
so that uplug_getPluginFile() works (i.e. icuinfo)
*/
uprv_strncpy(plugin_file, pluginFile.data(), sizeof(plugin_file));
#if UPLUG_TRACE
DBG((stderr, "pluginfile= %s len %d/%d\n", plugin_file, (int)strlen(plugin_file), (int)sizeof(plugin_file)));
#endif
#ifdef __MVS__
if (iscics()) /* 12 Nov 2011 JAM */
{
f = NULL;
}
else
#endif
{
f = fopen(pluginFile.data(), "r");
}
if(f != NULL) {
char linebuf[1024];
char *p, *libName=NULL, *symName=NULL, *config=NULL;
int32_t line = 0;
while(fgets(linebuf,1023,f)) {
line++;
if(!*linebuf || *linebuf=='#') {
continue;
} else {
p = linebuf;
while(*p&&isspace((int)*p))
p++;
if(!*p || *p=='#') continue;
libName = p;
while(*p&&!isspace((int)*p)) {
p++;
}
//.........这里部分代码省略.........