本文整理汇总了C++中UPRV_LENGTHOF函数的典型用法代码示例。如果您正苦于以下问题:C++ UPRV_LENGTHOF函数的具体用法?C++ UPRV_LENGTHOF怎么用?C++ UPRV_LENGTHOF使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UPRV_LENGTHOF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: errorCode
void UTS46Test::TestSomeCases() {
IcuTestErrorCode errorCode(*this, "TestSomeCases");
char buffer[400], buffer2[400];
int32_t i;
for(i=0; i<UPRV_LENGTHOF(testCases); ++i) {
const TestCase &testCase=testCases[i];
UnicodeString input(ctou(testCase.s));
UnicodeString expected(ctou(testCase.u));
// ToASCII/ToUnicode, transitional/nontransitional
UnicodeString aT, uT, aN, uN;
IDNAInfo aTInfo, uTInfo, aNInfo, uNInfo;
trans->nameToASCII(input, aT, aTInfo, errorCode);
trans->nameToUnicode(input, uT, uTInfo, errorCode);
nontrans->nameToASCII(input, aN, aNInfo, errorCode);
nontrans->nameToUnicode(input, uN, uNInfo, errorCode);
if(errorCode.logIfFailureAndReset("first-level processing [%d/%s] %s",
(int)i, testCase.o, testCase.s)
) {
continue;
}
// ToUnicode does not set length-overflow errors.
uint32_t uniErrors=testCase.errors&~
(UIDNA_ERROR_LABEL_TOO_LONG|
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG);
char mode=testCase.o[0];
if(mode=='B' || mode=='N') {
if(uNInfo.getErrors()!=uniErrors) {
errln("N.nameToUnicode([%d] %s) unexpected errors %04lx",
(int)i, testCase.s, (long)uNInfo.getErrors());
continue;
}
if(uN!=expected) {
prettify(uN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("N.nameToUnicode([%d] %s) unexpected string %s",
(int)i, testCase.s, buffer);
continue;
}
if(aNInfo.getErrors()!=testCase.errors) {
errln("N.nameToASCII([%d] %s) unexpected errors %04lx",
(int)i, testCase.s, (long)aNInfo.getErrors());
continue;
}
}
if(mode=='B' || mode=='T') {
if(uTInfo.getErrors()!=uniErrors) {
errln("T.nameToUnicode([%d] %s) unexpected errors %04lx",
(int)i, testCase.s, (long)uTInfo.getErrors());
continue;
}
if(uT!=expected) {
prettify(uT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("T.nameToUnicode([%d] %s) unexpected string %s",
(int)i, testCase.s, buffer);
continue;
}
if(aTInfo.getErrors()!=testCase.errors) {
errln("T.nameToASCII([%d] %s) unexpected errors %04lx",
(int)i, testCase.s, (long)aTInfo.getErrors());
continue;
}
}
// ToASCII is all-ASCII if no severe errors
if((aNInfo.getErrors()&severeErrors)==0 && !isASCII(aN)) {
prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("N.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
(int)i, testCase.s, aNInfo.getErrors(), buffer);
continue;
}
if((aTInfo.getErrors()&severeErrors)==0 && !isASCII(aT)) {
prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("T.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
(int)i, testCase.s, aTInfo.getErrors(), buffer);
continue;
}
if(verbose) {
char m= mode=='B' ? mode : 'N';
prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
logln("%c.nameToASCII([%d] %s) (errors %04lx) result string: %s",
m, (int)i, testCase.s, aNInfo.getErrors(), buffer);
if(mode!='B') {
prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
logln("T.nameToASCII([%d] %s) (errors %04lx) result string: %s",
(int)i, testCase.s, aTInfo.getErrors(), buffer);
}
}
// second-level processing
UnicodeString aTuN, uTaN, aNuN, uNaN;
IDNAInfo aTuNInfo, uTaNInfo, aNuNInfo, uNaNInfo;
nontrans->nameToUnicode(aT, aTuN, aTuNInfo, errorCode);
nontrans->nameToASCII(uT, uTaN, uTaNInfo, errorCode);
nontrans->nameToUnicode(aN, aNuN, aNuNInfo, errorCode);
nontrans->nameToASCII(uN, uNaN, uNaNInfo, errorCode);
if(errorCode.logIfFailureAndReset("second-level processing [%d/%s] %s",
(int)i, testCase.o, testCase.s)
) {
continue;
}
if(aN!=uNaN) {
prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(uNaN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
//.........这里部分代码省略.........
示例2: nextChar
//------------------------------------------------------------------------------
//
// Parse RBBI rules. The state machine for rules parsing is here.
// The state tables are hand-written in the file rbbirpt.txt,
// and converted to the form used here by a perl
// script rbbicst.pl
//
//------------------------------------------------------------------------------
void RBBIRuleScanner::parse() {
uint16_t state;
const RBBIRuleTableEl *tableEl;
if (U_FAILURE(*fRB->fStatus)) {
return;
}
state = 1;
nextChar(fC);
//
// Main loop for the rule parsing state machine.
// Runs once per state transition.
// Each time through optionally performs, depending on the state table,
// - an advance to the the next input char
// - an action to be performed.
// - pushing or popping a state to/from the local state return stack.
//
for (;;) {
// Bail out if anything has gone wrong.
// RBBI rule file parsing stops on the first error encountered.
if (U_FAILURE(*fRB->fStatus)) {
break;
}
// Quit if state == 0. This is the normal way to exit the state machine.
//
if (state == 0) {
break;
}
// Find the state table element that matches the input char from the rule, or the
// class of the input character. Start with the first table row for this
// state, then linearly scan forward until we find a row that matches the
// character. The last row for each state always matches all characters, so
// the search will stop there, if not before.
//
tableEl = &gRuleParseStateTable[state];
#ifdef RBBI_DEBUG
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) {
RBBIDebugPrintf("char, line, col = (\'%c\', %d, %d) state=%s ",
fC.fChar, fLineNum, fCharNum, RBBIRuleStateNames[state]);
}
#endif
for (;;) {
#ifdef RBBI_DEBUG
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPrintf("."); fflush(stdout);}
#endif
if (tableEl->fCharClass < 127 && fC.fEscaped == FALSE && tableEl->fCharClass == fC.fChar) {
// Table row specified an individual character, not a set, and
// the input character is not escaped, and
// the input character matched it.
break;
}
if (tableEl->fCharClass == 255) {
// Table row specified default, match anything character class.
break;
}
if (tableEl->fCharClass == 254 && fC.fEscaped) {
// Table row specified "escaped" and the char was escaped.
break;
}
if (tableEl->fCharClass == 253 && fC.fEscaped &&
(fC.fChar == 0x50 || fC.fChar == 0x70 )) {
// Table row specified "escaped P" and the char is either 'p' or 'P'.
break;
}
if (tableEl->fCharClass == 252 && fC.fChar == (UChar32)-1) {
// Table row specified eof and we hit eof on the input.
break;
}
if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class &&
fC.fEscaped == FALSE && // char is not escaped &&
fC.fChar != (UChar32)-1) { // char is not EOF
U_ASSERT((tableEl->fCharClass-128) < UPRV_LENGTHOF(fRuleSets));
if (fRuleSets[tableEl->fCharClass-128].contains(fC.fChar)) {
// Table row specified a character class, or set of characters,
// and the current char matches it.
break;
}
}
// No match on this row, advance to the next row for this state,
tableEl++;
}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPuts("");}
//
// We've found the row of the state table that matches the current input
// character from the rules string.
//.........这里部分代码省略.........
示例3:
ScriptSet &ScriptSet::resetAll() {
for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
bits[i] = 0;
}
return *this;
}
示例4:
UnhandledEngine::UnhandledEngine(UErrorCode &/*status*/) {
for (int32_t i = 0; i < UPRV_LENGTHOF(fHandled); ++i) {
fHandled[i] = 0;
}
}
示例5: udata_swap
U_CAPI int32_t U_EXPORT2
udata_swap(const UDataSwapper *ds,
const void *inData, int32_t length, void *outData,
UErrorCode *pErrorCode) {
char dataFormatChars[4];
const UDataInfo *pInfo;
int32_t i, swappedLength;
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
return 0;
}
/*
* Preflight the header first; checks for illegal arguments, too.
* Do not swap the header right away because the format-specific swapper
* will swap it, get the headerSize again, and also use the header
* information. Otherwise we would have to pass some of the information
* and not be able to use the UDataSwapFn signature.
*/
udata_swapDataHeader(ds, inData, -1, NULL, pErrorCode);
/*
* If we wanted udata_swap() to also handle non-loadable data like a UTrie,
* then we could check here for further known magic values and structures.
*/
if(U_FAILURE(*pErrorCode)) {
return 0; /* the data format was not recognized */
}
pInfo=(const UDataInfo *)((const char *)inData+4);
{
/* convert the data format from ASCII to Unicode to the system charset */
UChar u[4]={
pInfo->dataFormat[0], pInfo->dataFormat[1],
pInfo->dataFormat[2], pInfo->dataFormat[3]
};
if(uprv_isInvariantUString(u, 4)) {
u_UCharsToChars(u, dataFormatChars, 4);
} else {
dataFormatChars[0]=dataFormatChars[1]=dataFormatChars[2]=dataFormatChars[3]='?';
}
}
/* dispatch to the swap function for the dataFormat */
for(i=0; i<UPRV_LENGTHOF(swapFns); ++i) {
if(0==memcmp(swapFns[i].dataFormat, pInfo->dataFormat, 4)) {
swappedLength=swapFns[i].swapFn(ds, inData, length, outData, pErrorCode);
if(U_FAILURE(*pErrorCode)) {
udata_printError(ds, "udata_swap(): failure swapping data format %02x.%02x.%02x.%02x (\"%c%c%c%c\") - %s\n",
pInfo->dataFormat[0], pInfo->dataFormat[1],
pInfo->dataFormat[2], pInfo->dataFormat[3],
dataFormatChars[0], dataFormatChars[1],
dataFormatChars[2], dataFormatChars[3],
u_errorName(*pErrorCode));
} else if(swappedLength<(length-15)) {
/* swapped less than expected */
udata_printError(ds, "udata_swap() warning: swapped only %d out of %d bytes - data format %02x.%02x.%02x.%02x (\"%c%c%c%c\")\n",
swappedLength, length,
pInfo->dataFormat[0], pInfo->dataFormat[1],
pInfo->dataFormat[2], pInfo->dataFormat[3],
dataFormatChars[0], dataFormatChars[1],
dataFormatChars[2], dataFormatChars[3],
u_errorName(*pErrorCode));
}
return swappedLength;
}
}
/* the dataFormat was not recognized */
udata_printError(ds, "udata_swap(): unknown data format %02x.%02x.%02x.%02x (\"%c%c%c%c\")\n",
pInfo->dataFormat[0], pInfo->dataFormat[1],
pInfo->dataFormat[2], pInfo->dataFormat[3],
dataFormatChars[0], dataFormatChars[1],
dataFormatChars[2], dataFormatChars[3]);
*pErrorCode=U_UNSUPPORTED_ERROR;
return 0;
}
示例6: TestSelector
static void TestSelector()
{
TestText text;
USet* excluded_sets[3] = { NULL };
int32_t i, testCaseIdx;
if (!getAvailableNames()) {
return;
}
if (!text_open(&text)) {
releaseAvailableNames();;
}
excluded_sets[0] = uset_openEmpty();
for(i = 1 ; i < 3 ; i++) {
excluded_sets[i] = uset_open(i*30, i*30+500);
}
for(testCaseIdx = 0; testCaseIdx < UPRV_LENGTHOF(getEncodingsFns); testCaseIdx++)
{
int32_t excluded_set_id;
int32_t num_encodings;
const char **encodings = getEncodingsFns[testCaseIdx](&num_encodings);
if (getTestOption(QUICK_OPTION) && num_encodings > 25) {
uprv_free((void *)encodings);
continue;
}
/*
* for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++)
*
* This loop was replaced by the following statement because
* the loop made the test run longer without adding to the code coverage.
* The handling of the exclusion set is independent of the
* set of encodings, so there is no need to test every combination.
*/
excluded_set_id = testCaseIdx % UPRV_LENGTHOF(excluded_sets);
{
UConverterSelector *sel_rt, *sel_fb;
char *buffer_fb = NULL;
UErrorCode status = U_ZERO_ERROR;
sel_rt = ucnvsel_open(encodings, num_encodings,
excluded_sets[excluded_set_id],
UCNV_ROUNDTRIP_SET, &status);
if (num_encodings == gCountAvailable) {
/* test the special "all converters" parameter values */
sel_fb = ucnvsel_open(NULL, 0,
excluded_sets[excluded_set_id],
UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
} else if (uset_isEmpty(excluded_sets[excluded_set_id])) {
/* test that a NULL set gives the same results as an empty set */
sel_fb = ucnvsel_open(encodings, num_encodings,
NULL,
UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
} else {
sel_fb = ucnvsel_open(encodings, num_encodings,
excluded_sets[excluded_set_id],
UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status);
}
if (U_FAILURE(status)) {
log_err("ucnv_sel_open(encodings %ld) failed - %s\n", testCaseIdx, u_errorName(status));
ucnvsel_close(sel_rt);
uprv_free((void *)encodings);
continue;
}
text_reset(&text);
for (;;) {
UBool *manual_rt, *manual_fb;
static UChar utf16[10000];
char *s;
int32_t length8, length16;
s = text_nextString(&text, &length8);
if (s == NULL || (getTestOption(QUICK_OPTION) && text.number > 3)) {
break;
}
manual_rt = getResultsManually(encodings, num_encodings,
s, length8,
excluded_sets[excluded_set_id],
UCNV_ROUNDTRIP_SET);
manual_fb = getResultsManually(encodings, num_encodings,
s, length8,
excluded_sets[excluded_set_id],
UCNV_ROUNDTRIP_AND_FALLBACK_SET);
/* UTF-8 with length */
status = U_ZERO_ERROR;
verifyResult(ucnvsel_selectForUTF8(sel_rt, s, length8, &status), manual_rt);
verifyResult(ucnvsel_selectForUTF8(sel_fb, s, length8, &status), manual_fb);
/* UTF-8 NUL-terminated */
verifyResult(ucnvsel_selectForUTF8(sel_rt, s, -1, &status), manual_rt);
verifyResult(ucnvsel_selectForUTF8(sel_fb, s, -1, &status), manual_fb);
u_strFromUTF8(utf16, UPRV_LENGTHOF(utf16), &length16, s, length8, &status);
if (U_FAILURE(status)) {
log_err("error converting the test text (string %ld) to UTF-16 - %s\n",
(long)text.number, u_errorName(status));
} else {
if (text.number == 0) {
//.........这里部分代码省略.........
示例7: Locale
void
NewResourceBundleTest::TestIteration()
{
UErrorCode err = U_ZERO_ERROR;
const char* testdatapath;
const char* data[]={
"string_in_Root_te_te_IN", "1",
"array_in_Root_te_te_IN", "5",
"array_2d_in_Root_te_te_IN", "4",
};
Locale *locale=new Locale("te_IN");
testdatapath=loadTestData(err);
if(U_FAILURE(err))
{
dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
return;
}
ResourceBundle test1(testdatapath, *locale, err);
if(U_FAILURE(err)){
errln("Construction failed");
}
uint32_t i;
int32_t count, row=0, col=0;
char buf[5];
UnicodeString expected;
UnicodeString element("TE_IN");
UnicodeString action;
for(i=0; i<UPRV_LENGTHOF(data); i=i+2){
action = "te_IN";
action +=".get(";
action += data[i];
action +=", err)";
err=U_ZERO_ERROR;
ResourceBundle bundle = test1.get(data[i], err);
if(!U_FAILURE(err)){
action = "te_IN";
action +=".getKey()";
CONFIRM_EQ((UnicodeString)bundle.getKey(), (UnicodeString)data[i]);
count=0;
row=0;
while(bundle.hasNext()){
action = data[i];
action +=".getNextString(err)";
row=count;
UnicodeString got=bundle.getNextString(err);
if(U_SUCCESS(err)){
expected=element;
if(bundle.getSize() > 1){
CONFIRM_EQ(bundle.getType(), URES_ARRAY);
expected+=itoa(row, buf);
ResourceBundle rowbundle=bundle.get(row, err);
if(!U_FAILURE(err) && rowbundle.getSize()>1){
col=0;
while(rowbundle.hasNext()){
expected=element;
got=rowbundle.getNextString(err);
if(!U_FAILURE(err)){
expected+=itoa(row, buf);
expected+=itoa(col, buf);
col++;
CONFIRM_EQ(got, expected);
}
}
CONFIRM_EQ(col, rowbundle.getSize());
}
}
else{
CONFIRM_EQ(bundle.getType(), (int32_t)URES_STRING);
}
}
CONFIRM_EQ(got, expected);
count++;
}
action = data[i];
action +=".getSize()";
CONFIRM_EQ(bundle.getSize(), count);
CONFIRM_EQ(count, atoi(data[i+1]));
//after reaching the end
err=U_ZERO_ERROR;
ResourceBundle errbundle=bundle.getNext(err);
action = "After reaching the end of the Iterator:- ";
action +=data[i];
action +=".getNext()";
CONFIRM_NE(err, (int32_t)U_ZERO_ERROR);
CONFIRM_EQ(u_errorName(err), u_errorName(U_INDEX_OUTOFBOUNDS_ERROR));
//reset the iterator
err = U_ZERO_ERROR;
bundle.resetIterator();
/* The following code is causing a crash
****CRASH******
*/
bundle.getNext(err);
//.........这里部分代码省略.........
示例8: CheckLocale
void CompactDecimalFormatTest::TestCsShort() {
CheckLocale("cs", UNUM_SHORT, kCsShort, UPRV_LENGTHOF(kCsShort));
}
示例9: main
int
main(int argc,
char* argv[])
{
UErrorCode status = U_ZERO_ERROR;
const char *arg = NULL;
const char *outputDir = NULL; /* NULL = no output directory, use current */
const char *inputDir = NULL;
const char *encoding = "";
int i;
UBool illegalArg = FALSE;
U_MAIN_INIT_ARGS(argc, argv);
options[JAVA_PACKAGE].value = "com.ibm.icu.impl.data";
options[BUNDLE_NAME].value = "LocaleElements";
argc = u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);
/* error handling, printing usage message */
if(argc<0) {
fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]);
illegalArg = TRUE;
} else if(argc<2) {
illegalArg = TRUE;
}
if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) {
fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]);
illegalArg = TRUE;
}
if(options[FORMAT_VERSION].doesOccur) {
const char *s = options[FORMAT_VERSION].value;
if(uprv_strlen(s) != 1 || (s[0] < '1' && '3' < s[0])) {
fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s);
illegalArg = TRUE;
} else if(s[0] == '1' &&
(options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur)
) {
fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]);
illegalArg = TRUE;
} else {
setFormatVersion(s[0] - '0');
}
}
if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) &&
!options[WRITE_JAVA].doesOccur) {
fprintf(stderr,
"%s error: command line argument --java-package or --bundle-name "
"without --write-java\n",
argv[0]);
illegalArg = TRUE;
}
if(options[VERSION].doesOccur) {
fprintf(stderr,
"%s version %s (ICU version %s).\n"
"%s\n",
argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING);
if(!illegalArg) {
return U_ZERO_ERROR;
}
}
if(illegalArg || options[HELP1].doesOccur || options[HELP2].doesOccur) {
/*
* Broken into chunks because the C89 standard says the minimum
* required supported string length is 509 bytes.
*/
fprintf(stderr,
"Usage: %s [OPTIONS] [FILES]\n"
"\tReads the list of resource bundle source files and creates\n"
"\tbinary version of resource bundles (.res files)\n",
argv[0]);
fprintf(stderr,
"Options:\n"
"\t-h or -? or --help this usage text\n"
"\t-q or --quiet do not display warnings\n"
"\t-v or --verbose print extra information when processing files\n"
"\t-V or --version prints out version number and exits\n"
"\t-c or --copyright include copyright notice\n");
fprintf(stderr,
"\t-e or --encoding encoding of source files\n"
"\t-d of --destdir destination directory, followed by the path, defaults to %s\n"
"\t-s or --sourcedir source directory for files followed by path, defaults to %s\n"
"\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
"\t followed by path, defaults to %s\n",
u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory());
fprintf(stderr,
"\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n"
"\t defaults to ASCII and \\uXXXX format.\n"
"\t --java-package For --write-java: package name for writing the ListResourceBundle,\n"
"\t defaults to com.ibm.icu.impl.data\n");
fprintf(stderr,
"\t-b or --bundle-name For --write-java: root resource bundle name for writing the ListResourceBundle,\n"
"\t defaults to LocaleElements\n"
"\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n"
"\t an optional output file name.\n"
"\t-k or --strict use pedantic parsing of syntax\n"
/*added by Jing*/
"\t-l or --language for XLIFF: language code compliant with BCP 47.\n");
//.........这里部分代码省略.........
示例10: TestExponential
/* Test exponential pattern*/
static void TestExponential(void)
{
int32_t pat_length, val_length, lval_length;
int32_t ival, ilval, p, v, lneed;
UNumberFormat *fmt;
int32_t ppos;
UChar *upat;
UChar pattern[20];
UChar *str=NULL;
UChar uvalfor[20], ulvalfor[20];
char tempMsgBug[256];
double a;
UErrorCode status = U_ZERO_ERROR;
#if U_PLATFORM == U_PF_OS390
static const double val[] = { 0.01234, 123456789, 1.23e75, -3.141592653e-78 };
#else
static const double val[] = { 0.01234, 123456789, 1.23e300, -3.141592653e-271 };
#endif
static const char* pat[] = { "0.####E0", "00.000E00", "##0.######E000", "0.###E0;[0.###E0]" };
static const int32_t lval[] = { 0, -1, 1, 123456789 };
static const char* valFormat[] =
{
"1.234E-2", "1.2346E8", "1.23E300", "-3.1416E-271",
"12.340E-03", "12.346E07", "12.300E299", "-31.416E-272",
"12.34E-003", "123.4568E006", "1.23E300", "-314.1593E-273",
"1.234E-2", "1.235E8", "1.23E300", "[3.142E-271]"
};
static const char* lvalFormat[] =
{
"0E0", "-1E0", "1E0", "1.2346E8",
"00.000E00", "-10.000E-01", "10.000E-01", "12.346E07",
"0E000", "-1E000", "1E000", "123.4568E006",
"0E0", "[1E0]", "1E0", "1.235E8"
};
static const double valParse[] =
{
#if U_PLATFORM == U_PF_OS390
0.01234, 123460000, 1.23E75, -3.1416E-78,
0.01234, 123460000, 1.23E75, -3.1416E-78,
0.01234, 123456800, 1.23E75, -3.141593E-78,
0.01234, 123500000, 1.23E75, -3.142E-78
#else
/* We define the whole IEEE 754 number in the 4th column because
Visual Age 7 has a bug in rounding numbers. */
0.01234, 123460000, 1.23E300, -3.1415999999999999E-271,
0.01234, 123460000, 1.23E300, -3.1415999999999999E-271,
0.01234, 123456800, 1.23E300, -3.1415929999999999E-271,
0.01234, 123500000, 1.23E300, -3.1420000000000001E-271
#endif
};
static const int32_t lvalParse[] =
{
0, -1, 1, 123460000,
0, -1, 1, 123460000,
0, -1, 1, 123456800,
0, -1, 1, 123500000
};
pat_length = UPRV_LENGTHOF(pat);
val_length = UPRV_LENGTHOF(val);
lval_length = UPRV_LENGTHOF(lval);
ival = 0;
ilval = 0;
for (p=0; p < pat_length; ++p)
{
upat=(UChar*)malloc(sizeof(UChar) * (strlen(pat[p])+1) );
u_uastrcpy(upat, pat[p]);
fmt=unum_open(UNUM_IGNORE,upat, u_strlen(upat), "en_US",NULL, &status);
if (U_FAILURE(status)) {
log_err_status(status, "FAIL: Bad status returned by Number format construction with pattern %s -> %s\n", pat[p], u_errorName(status));
continue;
}
lneed= u_strlen(upat) + 1;
unum_toPattern(fmt, FALSE, pattern, lneed, &status);
log_verbose("Pattern \" %s \" -toPattern-> \" %s \" \n", upat, u_austrcpy(tempMsgBug, pattern) );
for (v=0; v<val_length; ++v)
{
/*format*/
lneed=0;
lneed=unum_formatDouble(fmt, val[v], NULL, lneed, NULL, &status);
if(status==U_BUFFER_OVERFLOW_ERROR){
status=U_ZERO_ERROR;
str=(UChar*)malloc(sizeof(UChar) * (lneed+1) );
unum_formatDouble(fmt, val[v], str, lneed+1, NULL, &status);
}
if(U_FAILURE(status)) {
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status) );
}
u_uastrcpy(uvalfor, valFormat[v+ival]);
if(u_strcmp(str, uvalfor) != 0)
log_verbose("FAIL: Expected %s ( %s )\n", valFormat[v+ival], u_austrcpy(tempMsgBug, uvalfor) );
/*parsing*/
ppos=0;
//.........这里部分代码省略.........
示例11: TestCurrencyKeywords
static void TestCurrencyKeywords(void)
{
static const char * const currencies[] = {
"ADD", "ADP", "AED", "AFA", "AFN", "AIF", "ALK", "ALL", "ALV", "ALX", "AMD",
"ANG", "AOA", "AOK", "AON", "AOR", "AOS", "ARA", "ARM", "ARP", "ARS", "ATS",
"AUD", "AUP", "AWG", "AZM", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF",
"BEL", "BGL", "BGM", "BGN", "BGO", "BGX", "BHD", "BIF", "BMD", "BMP", "BND",
"BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ",
"BSD", "BSP", "BTN", "BTR", "BUK", "BUR", "BWP", "BYB", "BYL", "BYR", "BZD",
"BZH", "CAD", "CDF", "CDG", "CDL", "CFF", "CHF", "CKD", "CLC", "CLE", "CLF",
"CLP", "CMF", "CNP", "CNX", "CNY", "COB", "COF", "COP", "CRC", "CSC", "CSK",
"CUP", "CUX", "CVE", "CWG", "CYP", "CZK", "DDM", "DEM", "DES", "DJF", "DKK",
"DOP", "DZD", "DZF", "DZG", "ECS", "ECV", "EEK", "EGP", "ERN", "ESP", "ETB",
"ETD", "EUR", "FIM", "FIN", "FJD", "FJP", "FKP", "FOK", "FRF", "FRG", "GAF",
"GBP", "GEK", "GEL", "GHC", "GHO", "GHP", "GHR", "GIP", "GLK", "GMD", "GMP",
"GNF", "GNI", "GNS", "GPF", "GQE", "GQF", "GQP", "GRD", "GRN", "GTQ", "GUF",
"GWE", "GWM", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IBP",
"IDG", "IDJ", "IDN", "IDR", "IEP", "ILL", "ILP", "ILS", "IMP", "INR", "IQD",
"IRR", "ISK", "ITL", "JEP", "JMD", "JMP", "JOD", "JPY", "KES", "KGS", "KHO",
"KHR", "KID", "KMF", "KPP", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZR",
"KZT", "LAK", "LBP", "LIF", "LKR", "LNR", "LRD", "LSL", "LTL", "LTT", "LUF",
"LVL", "LVR", "LYB", "LYD", "LYP", "MAD", "MAF", "MCF", "MCG", "MDC", "MDL",
"MDR", "MGA", "MGF", "MHD", "MKD", "MKN", "MLF", "MMK", "MMX", "MNT", "MOP",
"MQF", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MWP", "MXN", "MXP",
"MXV", "MYR", "MZE", "MZM", "NAD", "NCF", "NGN", "NGP", "NHF", "NIC", "NIG",
"NIO", "NLG", "NOK", "NPR", "NZD", "NZP", "OMR", "OMS", "PAB", "PDK", "PDN",
"PDR", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLX", "PLZ", "PSP",
"PTC", "PTE", "PYG", "QAR", "REF", "ROL", "RON", "RUB", "RUR", "RWF", "SAR",
"SAS", "SBD", "SCR", "SDD", "SDP", "SEK", "SGD", "SHP", "SIB", "SIT", "SKK",
"SLL", "SML", "SOS", "SQS", "SRG", "SSP", "STD", "STE", "SUN", "SUR", "SVC",
"SYP", "SZL", "TCC", "TDF", "THB", "TJR", "TJS", "TMM", "TND", "TOP", "TOS",
"TPE", "TPP", "TRL", "TTD", "TTO", "TVD", "TWD", "TZS", "UAH", "UAK", "UGS",
"UGX", "USD", "USN", "USS", "UYF", "UYP", "UYU", "UZC", "UZS", "VAL", "VDD",
"VDN", "VDP", "VEB", "VGD", "VND", "VNN", "VNR", "VNS", "VUV", "WSP", "WST",
"XAD", "XAF", "XAM", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XCF", "XDR",
"XEF", "XEU", "XFO", "XFU", "XID", "XMF", "XNF", "XOF", "XPF", "XPS", "XSS",
"XTR", "YDD", "YEI", "YER", "YUD", "YUF", "YUG", "YUM", "YUN", "YUO", "YUR",
"ZAL", "ZAP", "ZAR", "ZMK", "ZMP", "ZRN", "ZRZ", "ZWD"
};
UErrorCode status = U_ZERO_ERROR;
int32_t i = 0, j = 0;
int32_t noLocales = uloc_countAvailable();
char locale[256];
char currLoc[256];
UChar result[4];
UChar currBuffer[256];
for(i = 0; i < noLocales; i++) {
strcpy(currLoc, uloc_getAvailable(i));
for(j = 0; j < UPRV_LENGTHOF(currencies); j++) {
strcpy(locale, currLoc);
strcat(locale, "@currency=");
strcat(locale, currencies[j]);
ucurr_forLocale(locale, result, 4, &status);
u_charsToUChars(currencies[j], currBuffer, 3);
currBuffer[3] = 0;
if(u_strcmp(currBuffer, result) != 0) {
log_err("Didn't get the right currency for %s\n", locale);
}
}
}
}
示例12: checkData
void BytesTrieTest::TestEmpty() {
static const StringAndValue data[]={
{ "", 0 }
};
checkData(data, UPRV_LENGTHOF(data));
}
示例13: UPRV_LENGTHOF
}
param[] =
{
// "te" means test
// "IN" means inherits
// "NE" or "ne" means "does not exist"
{ "root", 0, U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } },
{ "te", 0, U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
{ "te_IN", 0, U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
{ "te_NE", 0, U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
{ "te_IN_NE", 0, U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
{ "ne", 0, U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
};
static int32_t bundles_count = UPRV_LENGTHOF(param);
//***************************************************************************************
/**
* Return a random unsigned long l where 0N <= l <= ULONG_MAX.
*/
static uint32_t
randul()
{
static UBool initialized = FALSE;
if (!initialized)
{
srand((unsigned)time(NULL));
initialized = TRUE;
示例14: UnicodeString
//.........这里部分代码省略.........
}
delete p;
UVersionInfo ver;
copyRes.getVersion(ver);
logln("Version returned: [%d.%d.%d.%d]\n", ver[0], ver[1], ver[2], ver[3]);
logln("Testing C like UnicodeString APIs\n");
UResourceBundle *testCAPI = NULL, *bundle = NULL, *rowbundle = NULL, *temp = NULL;
err = U_ZERO_ERROR;
const char* data[]={
"string_in_Root_te_te_IN", "1",
"array_in_Root_te_te_IN", "5",
"array_2d_in_Root_te_te_IN", "4",
};
testCAPI = ures_open(testdatapath, "te_IN", &err);
if(U_SUCCESS(err)) {
// Do the testing
// first iteration
uint32_t i;
int32_t count, row=0, col=0;
char buf[5];
UnicodeString expected;
UnicodeString element("TE_IN");
UnicodeString action;
for(i=0; i<UPRV_LENGTHOF(data); i=i+2){
action = "te_IN";
action +=".get(";
action += data[i];
action +=", err)";
err=U_ZERO_ERROR;
bundle = ures_getByKey(testCAPI, data[i], bundle, &err);
if(!U_FAILURE(err)){
const char* key = NULL;
action = "te_IN";
action +=".getKey()";
CONFIRM_EQ((UnicodeString)ures_getKey(bundle), (UnicodeString)data[i]);
count=0;
row=0;
while(ures_hasNext(bundle)){
action = data[i];
action +=".getNextString(err)";
row=count;
UnicodeString got=ures_getNextUnicodeString(bundle, &key, &err);
if(U_SUCCESS(err)){
expected=element;
if(ures_getSize(bundle) > 1){
CONFIRM_EQ(ures_getType(bundle), URES_ARRAY);
expected+=itoa(row, buf);
rowbundle=ures_getByIndex(bundle, row, rowbundle, &err);
if(!U_FAILURE(err) && ures_getSize(rowbundle)>1){
col=0;
while(ures_hasNext(rowbundle)){
expected=element;
got=ures_getNextUnicodeString(rowbundle, &key, &err);
temp = ures_getByIndex(rowbundle, col, temp, &err);
示例15: printOutBundle
static void printOutBundle(UFILE *out, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status)
{
static const UChar cr[] = { 0xA }; // LF
/* int32_t noOfElements = ures_getSize(resource);*/
int32_t i = 0;
const char *key = ures_getKey(resource);
switch(ures_getType(resource)) {
case URES_STRING :
{
int32_t len=0;
const UChar* thestr = ures_getString(resource, &len, status);
UChar *string = quotedString(thestr);
/* TODO: String truncation */
if(opt_truncate && len > truncsize) {
char msg[128];
printIndent(out, indent);
sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n",
(long)len, (long)(truncsize/2));
printCString(out, msg, -1);
len = truncsize/2;
}
printIndent(out, indent);
if(key != NULL) {
static const UChar openStr[] = { 0x0020, 0x007B, 0x0020, 0x0022 }; /* " { \"" */
static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D }; /* "\" }" */
printCString(out, key, (int32_t)uprv_strlen(key));
printString(out, openStr, UPRV_LENGTHOF(openStr));
printString(out, string, len);
printString(out, closeStr, UPRV_LENGTHOF(closeStr));
} else {
static const UChar openStr[] = { 0x0022 }; /* "\"" */
static const UChar closeStr[] = { 0x0022, 0x002C }; /* "\"," */
printString(out, openStr, UPRV_LENGTHOF(openStr));
printString(out, string, (int32_t)(u_strlen(string)));
printString(out, closeStr, UPRV_LENGTHOF(closeStr));
}
if(verbose) {
printCString(out, "// STRING", -1);
}
printString(out, cr, UPRV_LENGTHOF(cr));
uprv_free(string);
}
break;
case URES_INT :
{
static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0020, 0x007B, 0x0020 }; /* ":int { " */
static const UChar closeStr[] = { 0x0020, 0x007D }; /* " }" */
UChar num[20];
printIndent(out, indent);
if(key != NULL) {
printCString(out, key, -1);
}
printString(out, openStr, UPRV_LENGTHOF(openStr));
uprv_itou(num, 20, ures_getInt(resource, status), 10, 0);
printString(out, num, u_strlen(num));
printString(out, closeStr, UPRV_LENGTHOF(closeStr));
if(verbose) {
printCString(out, "// INT", -1);
}
printString(out, cr, UPRV_LENGTHOF(cr));
break;
}
case URES_BINARY :
{
int32_t len = 0;
const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status);
if(opt_truncate && len > truncsize) {
char msg[128];
printIndent(out, indent);
sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n",
(long)len, (long)(truncsize/2));
printCString(out, msg, -1);
len = truncsize;
}
if(U_SUCCESS(*status)) {
static const UChar openStr[] = { 0x003A, 0x0062, 0x0069, 0x006E, 0x0061, 0x0072, 0x0079, 0x0020, 0x007B, 0x0020 }; /* ":binary { " */
static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */
printIndent(out, indent);
if(key != NULL) {
printCString(out, key, -1);
}
printString(out, openStr, UPRV_LENGTHOF(openStr));
for(i = 0; i<len; i++) {
printHex(out, *data++);
}
printString(out, closeStr, UPRV_LENGTHOF(closeStr));
if(verbose) {
printCString(out, " // BINARY", -1);
}
printString(out, cr, UPRV_LENGTHOF(cr));
} else {
//.........这里部分代码省略.........