本文整理汇总了C++中Formattable::getLong方法的典型用法代码示例。如果您正苦于以下问题:C++ Formattable::getLong方法的具体用法?C++ Formattable::getLong怎么用?C++ Formattable::getLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formattable
的用法示例。
在下文中一共展示了Formattable::getLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectPlural
StandardPlural::Form QuantityFormatter::selectPlural(
const Formattable &number,
const NumberFormat &fmt,
const PluralRules &rules,
UnicodeString &formattedNumber,
FieldPosition &pos,
UErrorCode &status) {
if (U_FAILURE(status)) {
return StandardPlural::OTHER;
}
UnicodeString pluralKeyword;
const DecimalFormat *decFmt = dynamic_cast<const DecimalFormat *>(&fmt);
if (decFmt != NULL) {
number::impl::DecimalQuantity dq;
decFmt->formatToDecimalQuantity(number, dq, status);
if (U_FAILURE(status)) {
return StandardPlural::OTHER;
}
pluralKeyword = rules.select(dq);
decFmt->format(number, formattedNumber, pos, status);
} else {
if (number.getType() == Formattable::kDouble) {
pluralKeyword = rules.select(number.getDouble());
} else if (number.getType() == Formattable::kLong) {
pluralKeyword = rules.select(number.getLong());
} else if (number.getType() == Formattable::kInt64) {
pluralKeyword = rules.select((double) number.getInt64());
} else {
status = U_ILLEGAL_ARGUMENT_ERROR;
return StandardPlural::OTHER;
}
fmt.format(number, formattedNumber, pos, status);
}
return StandardPlural::orOtherFromString(pluralKeyword);
}
示例2: NativeDecimalFormat_parse
static jobject NativeDecimalFormat_parse(JNIEnv* env, jclass, jlong addr, jstring text,
jobject position, jboolean parseBigDecimal) {
static jmethodID gPP_getIndex = env->GetMethodID(JniConstants::parsePositionClass, "getIndex", "()I");
static jmethodID gPP_setIndex = env->GetMethodID(JniConstants::parsePositionClass, "setIndex", "(I)V");
static jmethodID gPP_setErrorIndex = env->GetMethodID(JniConstants::parsePositionClass, "setErrorIndex", "(I)V");
ScopedJavaUnicodeString src(env, text);
if (!src.valid()) {
return NULL;
}
// make sure the ParsePosition is valid. Actually icu4c would parse a number
// correctly even if the parsePosition is set to -1, but since the RI fails
// for that case we have to fail too
int parsePos = env->CallIntMethod(position, gPP_getIndex, NULL);
if (parsePos < 0 || parsePos > env->GetStringLength(text)) {
return NULL;
}
Formattable res;
ParsePosition pp(parsePos);
DecimalFormat* fmt = toDecimalFormat(addr);
fmt->parse(src.unicodeString(), res, pp);
if (pp.getErrorIndex() == -1) {
env->CallVoidMethod(position, gPP_setIndex, pp.getIndex());
} else {
env->CallVoidMethod(position, gPP_setErrorIndex, pp.getErrorIndex());
return NULL;
}
if (parseBigDecimal) {
UErrorCode status = U_ZERO_ERROR;
StringPiece str = res.getDecimalNumber(status);
if (U_SUCCESS(status)) {
int len = str.length();
const char* data = str.data();
if (strncmp(data, "NaN", 3) == 0 ||
strncmp(data, "Inf", 3) == 0 ||
strncmp(data, "-Inf", 4) == 0) {
double resultDouble = res.getDouble(status);
return doubleValueOf(env, resultDouble);
}
return newBigDecimal(env, data, len);
}
return NULL;
}
switch (res.getType()) {
case Formattable::kDouble: return doubleValueOf(env, res.getDouble());
case Formattable::kLong: return longValueOf(env, res.getLong());
case Formattable::kInt64: return longValueOf(env, res.getInt64());
default: return NULL;
}
}
示例3: parseRes
U_CAPI int32_t U_EXPORT2
unum_parse( const UNumberFormat* fmt,
const UChar* text,
int32_t textLength,
int32_t *parsePos /* 0 = start */,
UErrorCode *status)
{
Formattable res;
parseRes(res, fmt, text, textLength, parsePos, FALSE, status);
return res.getLong(*status);
}
示例4: uprv_fabs
double
NumberFormatRoundTripTest::proportionalError(const Formattable& a, const Formattable& b)
{
double aa,bb;
if(isDouble(a))
aa = a.getDouble();
else
aa = a.getLong();
if(isDouble(b))
bb = b.getDouble();
else
bb = b.getLong();
double error = aa - bb;
if(aa != 0 && bb != 0)
error /= aa;
return uprv_fabs(error);
}
示例5: switch
void
FormattableStreamer::streamOut(ostream& stream, const Formattable& obj)
{
static DateFormat *defDateFormat = 0;
UnicodeString buffer;
switch(obj.getType()) {
case Formattable::kDate :
// Creates a DateFormat instance for formatting the
// Date instance.
if (defDateFormat == 0) {
defDateFormat = DateFormat::createInstance();
}
defDateFormat->format(obj.getDate(), buffer);
stream << buffer;
break;
case Formattable::kDouble :
// Output the double as is.
stream << obj.getDouble() << 'D';
break;
case Formattable::kLong :
// Output the double as is.
stream << obj.getLong() << 'L';
break;
case Formattable::kString:
// Output the double as is. Please see UnicodeString console
// I/O routine for more details.
stream << '"' << obj.getString(buffer) << '"';
break;
case Formattable::kArray:
int32_t i, count;
const Formattable* array;
array = obj.getArray(count);
stream << '[';
// Recursively calling the console I/O routine for each element in the array.
for (i=0; i<count; ++i) {
FormattableStreamer::streamOut(stream, array[i]);
stream << ( (i==(count-1)) ? "" : ", " );
}
stream << ']';
break;
default:
// Not a recognizable Formattable object.
stream << "INVALID_Formattable";
}
stream.flush();
}
示例6:
U_DRAFT int32_t U_EXPORT2
ufmt_getLong(UFormattable *fmt, UErrorCode *status) {
Formattable *obj = Formattable::fromUFormattable(fmt);
return obj->getLong(*status);
}
示例7: if
void
RbnfRoundTripTest::doTest(const RuleBasedNumberFormat* formatter,
double lowLimit,
double highLimit)
{
char buf[128];
uint32_t count = 0;
double increment = 1;
for (double i = lowLimit; i <= highLimit; i += increment) {
if (count % 1000 == 0) {
sprintf(buf, "%.12g", i);
logln(buf);
}
if (fabs(i) < 5000)
increment = 1;
else if (fabs(i) < 500000)
increment = 2737;
else
increment = 267437;
UnicodeString formatResult;
formatter->format(i, formatResult);
UErrorCode status = U_ZERO_ERROR;
Formattable parseResult;
formatter->parse(formatResult, parseResult, status);
if (U_FAILURE(status)) {
sprintf(buf, "Round-trip status failure: %.12g, status: %d", i, status);
errln(buf);
return;
} else {
double rt = (parseResult.getType() == Formattable::kDouble) ?
parseResult.getDouble() :
(double)parseResult.getLong();
if (rt != i) {
sprintf(buf, "Round-trip failed: %.12g -> %.12g", i, rt);
errln(buf);
return;
}
}
++count;
}
if (lowLimit < 0) {
double d = 1.234;
while (d < 1000) {
UnicodeString formatResult;
formatter->format(d, formatResult);
UErrorCode status = U_ZERO_ERROR;
Formattable parseResult;
formatter->parse(formatResult, parseResult, status);
if (U_FAILURE(status)) {
sprintf(buf, "Round-trip status failure: %.12g, status: %d", d, status);
errln(buf);
return;
} else {
double rt = (parseResult.getType() == Formattable::kDouble) ?
parseResult.getDouble() :
(double)parseResult.getLong();
if (rt != d) {
UnicodeString msg;
sprintf(buf, "Round-trip failed: %.12g -> ", d);
msg.append(buf);
msg.append(formatResult);
sprintf(buf, " -> %.12g", rt);
msg.append(buf);
errln(msg);
return;
}
}
d *= 10;
}
}
}
示例8: fpos
//.........这里部分代码省略.........
}
double d_a2[] = { 3.0, 4.0 };
UnicodeString s_a2[] = { "third", "forth" };
form_pat.setChoices( d_a2, s_a2, 2 );
form_pat.toPattern( res1 );
it_logln(UnicodeString("ChoiceFormat adoptChoices toPattern: ") + res1);
if (res1 == "3#third|4#forth") {
it_logln("ChoiceFormat adoptChoices tested");
}else{
it_errln("*** ChoiceFormat adoptChoices result!");
}
str = "";
fpos = 0;
status = U_ZERO_ERROR;
double arg_double = 3.0;
res1 = form_pat.format( arg_double, str, fpos );
it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (double, ...) result!");
str = "";
fpos = 0;
status = U_ZERO_ERROR;
int64_t arg_64 = 3;
res1 = form_pat.format( arg_64, str, fpos );
it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (int64_t, ...) result!");
str = "";
fpos = 0;
status = U_ZERO_ERROR;
int32_t arg_long = 3;
res1 = form_pat.format( arg_long, str, fpos );
it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (int32_t, ...) result!");
Formattable ft( (int32_t)3 );
str = "";
fpos = 0;
status = U_ZERO_ERROR;
res1 = form_pat.format( ft, str, fpos, status );
if (!chkstatus( status, "*** test_complex_example format (int32_t, ...)" )) {
delete fileform;
delete filenumform;
delete pattform;
return;
}
it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (Formattable, ...) result!");
Formattable fta[] = { (int32_t)3 };
str = "";
fpos = 0;
status = U_ZERO_ERROR;
res1 = form_pat.format( fta, 1, str, fpos, status );
if (!chkstatus( status, "*** test_complex_example format (int32_t, ...)" )) {
delete fileform;
delete filenumform;
delete pattform;
return;
}
it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (Formattable[], cnt, ...) result!");
ParsePosition parse_pos = 0;
Formattable result;
UnicodeString parsetext("third");
form_pat.parse( parsetext, result, parse_pos );
double rd = (result.getType() == Formattable::kLong) ? result.getLong() : result.getDouble();
if (rd == 3.0) {
it_logln("parse( ..., ParsePos ) tested.");
}else{
it_errln("*** ChoiceFormat parse( ..., ParsePos )!");
}
form_pat.parse( parsetext, result, status );
rd = (result.getType() == Formattable::kLong) ? result.getLong() : result.getDouble();
if (rd == 3.0) {
it_logln("parse( ..., UErrorCode ) tested.");
}else{
it_errln("*** ChoiceFormat parse( ..., UErrorCode )!");
}
/*
UClassID classID = ChoiceFormat::getStaticClassID();
if (classID == form_pat.getDynamicClassID()) {
it_out << "getStaticClassID and getDynamicClassID tested." << endl;
}else{
it_errln("*** getStaticClassID and getDynamicClassID!");
}
*/
it_logln();
delete fileform;
delete filenumform;
delete pattform;
}
示例9: test_Formattable
void test_Formattable( void )
{
UErrorCode status = U_ZERO_ERROR;
Formattable* ftp = new Formattable();
if (!ftp || !(ftp->getType() == Formattable::kLong) || !(ftp->getLong() == 0)) {
it_errln("*** Formattable constructor or getType or getLong");
}
delete ftp;
Formattable fta, ftb;
fta.setLong(1); ftb.setLong(2);
if ((fta != ftb) || !(fta == ftb)) {
it_logln("FT setLong, operator== and operator!= tested.");
status = U_ZERO_ERROR;
fta.getLong(&status);
if ( status == U_INVALID_FORMAT_ERROR){
it_errln("*** FT getLong(UErrorCode* status) failed on real Long");
} else {
it_logln("FT getLong(UErrorCode* status) tested.");
}
}else{
it_errln("*** Formattable setLong or operator== or !=");
}
fta = ftb;
if ((fta == ftb) || !(fta != ftb)) {
it_logln("FT operator= tested.");
}else{
it_errln("*** FT operator= or operator== or operator!=");
}
fta.setDouble( 3.0 );
if ((fta.getType() == Formattable::kDouble) && (fta.getDouble() == 3.0)) {
it_logln("FT set- and getDouble tested.");
}else{
it_errln("*** FT set- or getDouble");
}
fta.getDate(status = U_ZERO_ERROR);
if (status != U_INVALID_FORMAT_ERROR){
it_errln("*** FT getDate with status should fail on non-Date");
}
fta.setDate( 4.0 );
if ((fta.getType() == Formattable::kDate) && (fta.getDate() == 4.0)) {
it_logln("FT set- and getDate tested.");
status = U_ZERO_ERROR;
fta.getDate(status);
if ( status == U_INVALID_FORMAT_ERROR){
it_errln("*** FT getDate with status failed on real Date");
} else {
it_logln("FT getDate with status tested.");
}
}else{
it_errln("*** FT set- or getDate");
}
status = U_ZERO_ERROR;
fta.getLong(&status);
if (status != U_INVALID_FORMAT_ERROR){
it_errln("*** FT getLong(UErrorCode* status) should fail on non-Long");
}
fta.setString("abc");
const Formattable ftc(fta);
UnicodeString res;
{
UBool t;
t = (fta.getType() == Formattable::kString)
&& (fta.getString(res) == "abc")
&& (fta.getString() == "abc");
res = fta.getString(status = U_ZERO_ERROR);
t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc");
res = ftc.getString(status = U_ZERO_ERROR);
t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc");
ftc.getString(res,status = U_ZERO_ERROR);
t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc");
if (t) {
it_logln("FT set- and getString tested.");
}else{
it_errln("*** FT set- or getString");
}
}
UnicodeString ucs = "unicode-string";
UnicodeString* ucs_ptr = new UnicodeString("pointed-to-unicode-string");
const Formattable ftarray[] =
{
Formattable( 1.0, Formattable::kIsDate ),
2.0,
(int32_t)3,
ucs,
ucs_ptr
};
const int32_t ft_cnt = UPRV_LENGTHOF(ftarray);
Formattable ft_arr( ftarray, ft_cnt );
UnicodeString temp;
if ((ft_arr[0].getType() == Formattable::kDate) && (ft_arr[0].getDate() == 1.0)
&& (ft_arr[1].getType() == Formattable::kDouble) && (ft_arr[1].getDouble() == 2.0)
&& (ft_arr[2].getType() == Formattable::kLong) && (ft_arr[2].getLong() == (int32_t)3)
//.........这里部分代码省略.........
示例10: logln
void
NumberFormatRoundTripTest::test(NumberFormat *fmt, const Formattable& value)
{
fmt->setMaximumFractionDigits(999);
DecimalFormat *df = dynamic_cast<DecimalFormat *>(fmt);
if(df != NULL) {
df->setRoundingIncrement(0.0);
}
UErrorCode status = U_ZERO_ERROR;
UnicodeString s, s2, temp;
if(isDouble(value))
s = fmt->format(value.getDouble(), s);
else
s = fmt->format(value.getLong(), s);
Formattable n;
UBool show = verbose;
if(DEBUG_VAR)
logln(/*value.getString(temp) +*/ " F> " + escape(s));
fmt->parse(s, n, status);
failure(status, "fmt->parse");
if(DEBUG_VAR)
logln(escape(s) + " P> " /*+ n.getString(temp)*/);
if(isDouble(n))
s2 = fmt->format(n.getDouble(), s2);
else
s2 = fmt->format(n.getLong(), s2);
if(DEBUG_VAR)
logln(/*n.getString(temp) +*/ " F> " + escape(s2));
if(STRING_COMPARE) {
if (s != s2) {
errln("*** STRING ERROR \"" + escape(s) + "\" != \"" + escape(s2) + "\"");
show = TRUE;
}
}
if(EXACT_NUMERIC_COMPARE) {
if(value != n) {
errln("*** NUMERIC ERROR");
show = TRUE;
}
}
else {
// Compute proportional error
double error = proportionalError(value, n);
if(error > MAX_ERROR) {
errln(UnicodeString("*** NUMERIC ERROR ") + error);
show = TRUE;
}
if (error > max_numeric_error)
max_numeric_error = error;
if (error < min_numeric_error)
min_numeric_error = error;
}
if (show) {
errln(/*value.getString(temp) +*/ typeOf(value, temp) + " F> " +
escape(s) + " P> " + (n.getType() == Formattable::kDouble ? n.getDouble() : (double)n.getLong())
/*n.getString(temp) */ + typeOf(n, temp) + " F> " +
escape(s2));
}
}
示例11: pos
void MessageFormatRegressionTest::Test4031438()
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString pattern1("Impossible {1} has occurred -- status code is {0} and message is {2}.");
UnicodeString pattern2("Double '' Quotes {0} test and quoted '{1}' test plus 'other {2} stuff'.");
MessageFormat *messageFormatter = new MessageFormat("", status);
failure(status, "new MessageFormat");
const UBool possibleDataError = TRUE;
//try {
logln("Apply with pattern : " + pattern1);
messageFormatter->applyPattern(pattern1, status);
failure(status, "messageFormat->applyPattern");
//Object[] params = {new Integer(7)};
Formattable params []= {
Formattable((int32_t)7)
};
UnicodeString tempBuffer;
FieldPosition pos(FieldPosition::DONT_CARE);
tempBuffer = messageFormatter->format(params, 1, tempBuffer, pos, status);
if(tempBuffer != "Impossible {1} has occurred -- status code is 7 and message is {2}." || failure(status, "MessageFormat::format"))
dataerrln("Tests arguments < substitution failed");
logln("Formatted with 7 : " + tempBuffer);
ParsePosition pp(0);
int32_t count = 0;
Formattable *objs = messageFormatter->parse(tempBuffer, pp, count);
//if(objs[7/*params.length*/] != NULL)
// errln("Parse failed with more than expected arguments");
NumberFormat *fmt = 0;
UnicodeString temp, temp1;
for (int i = 0; i < count; i++) {
// convert to string if not already
Formattable obj = objs[i];
temp.remove();
if(obj.getType() == Formattable::kString)
temp = obj.getString(temp);
else {
fmt = NumberFormat::createInstance(status);
switch (obj.getType()) {
case Formattable::kLong: fmt->format(obj.getLong(), temp); break;
case Formattable::kInt64: fmt->format(obj.getInt64(), temp); break;
case Formattable::kDouble: fmt->format(obj.getDouble(), temp); break;
default: break;
}
}
// convert to string if not already
Formattable obj1 = params[i];
temp1.remove();
if(obj1.getType() == Formattable::kString)
temp1 = obj1.getString(temp1);
else {
fmt = NumberFormat::createInstance(status);
switch (obj1.getType()) {
case Formattable::kLong: fmt->format(obj1.getLong(), temp1); break;
case Formattable::kInt64: fmt->format(obj1.getInt64(), temp1); break;
case Formattable::kDouble: fmt->format(obj1.getDouble(), temp1); break;
default: break;
}
}
//if (objs[i] != NULL && objs[i].getString(temp1) != params[i].getString(temp2)) {
if (temp != temp1) {
errln("Parse failed on object " + objs[i].getString(temp1) + " at index : " + i);
}
}
delete fmt;
delete [] objs;
// {sfb} does this apply? no way to really pass a null Formattable,
// only a null array
/*tempBuffer = messageFormatter->format(null, tempBuffer, FieldPosition(FieldPosition::DONT_CARE), status);
if (tempBuffer != "Impossible {1} has occurred -- status code is {0} and message is {2}." || failure(status, "messageFormat->format"))
errln("Tests with no arguments failed");
logln("Formatted with null : " + tempBuffer);*/
logln("Apply with pattern : " + pattern2);
messageFormatter->applyPattern(pattern2, status);
failure(status, "messageFormatter->applyPattern", possibleDataError);
tempBuffer.remove();
tempBuffer = messageFormatter->format(params, 1, tempBuffer, pos, status);
if (tempBuffer != "Double ' Quotes 7 test and quoted {1} test plus other {2} stuff.")
dataerrln("quote format test (w/ params) failed. - %s", u_errorName(status));
logln("Formatted with params : " + tempBuffer);
/*tempBuffer = messageFormatter->format(null);
if (!tempBuffer.equals("Double ' Quotes {0} test and quoted {1} test plus other {2} stuff."))
errln("quote format test (w/ null) failed.");
logln("Formatted with null : " + tempBuffer);
logln("toPattern : " + messageFormatter.toPattern());*/
/*} catch (Exception foo) {
errln("Exception when formatting in bug 4031438. "+foo.getMessage());
}*/
//.........这里部分代码省略.........
示例12: parseRBNFImpl
static jobject parseRBNFImpl(JNIEnv *env, jclass clazz, jint addr, jstring text,
jobject position, jboolean lenient) {
// LOGI("ENTER parseRBNFImpl");
const char * parsePositionClassName = "java/text/ParsePosition";
const char * longClassName = "java/lang/Long";
const char * doubleClassName = "java/lang/Double";
UErrorCode status = U_ZERO_ERROR;
UNumberFormat *fmt = (UNumberFormat *)(int)addr;
jchar *str = (UChar *)env->GetStringChars(text, NULL);
int strlength = env->GetStringLength(text);
jclass parsePositionClass = env->FindClass(parsePositionClassName);
jclass longClass = env->FindClass(longClassName);
jclass doubleClass = env->FindClass(doubleClassName);
jmethodID getIndexMethodID = env->GetMethodID(parsePositionClass,
"getIndex", "()I");
jmethodID setIndexMethodID = env->GetMethodID(parsePositionClass,
"setIndex", "(I)V");
jmethodID setErrorIndexMethodID = env->GetMethodID(parsePositionClass,
"setErrorIndex", "(I)V");
jmethodID longInitMethodID = env->GetMethodID(longClass, "<init>", "(J)V");
jmethodID dblInitMethodID = env->GetMethodID(doubleClass, "<init>", "(D)V");
int parsePos = env->CallIntMethod(position, getIndexMethodID, NULL);
// make sure the ParsePosition is valid. Actually icu4c would parse a number
// correctly even if the parsePosition is set to -1, but since the RI fails
// for that case we have to fail too
if(parsePos < 0 || parsePos > strlength) {
return NULL;
}
Formattable res;
const UnicodeString src((UChar*)str, strlength, strlength);
ParsePosition pp;
pp.setIndex(parsePos);
if(lenient) {
unum_setAttribute(fmt, UNUM_LENIENT_PARSE, JNI_TRUE);
}
((const NumberFormat*)fmt)->parse(src, res, pp);
if(lenient) {
unum_setAttribute(fmt, UNUM_LENIENT_PARSE, JNI_FALSE);
}
env->ReleaseStringChars(text, str);
if(pp.getErrorIndex() == -1) {
parsePos = pp.getIndex();
} else {
env->CallVoidMethod(position, setErrorIndexMethodID,
(jint) pp.getErrorIndex());
return NULL;
}
Formattable::Type numType;
numType = res.getType();
UErrorCode fmtStatus;
double resultDouble;
long resultLong;
int64_t resultInt64;
switch(numType) {
case Formattable::kDouble:
resultDouble = res.getDouble();
env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
return env->NewObject(doubleClass, dblInitMethodID,
(jdouble) resultDouble);
case Formattable::kLong:
resultLong = res.getLong();
env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
return env->NewObject(longClass, longInitMethodID,
(jlong) resultLong);
case Formattable::kInt64:
resultInt64 = res.getInt64();
env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
return env->NewObject(longClass, longInitMethodID,
(jlong) resultInt64);
default:
break;
}
return NULL;
}
示例13: loadRegionData
//.........这里部分代码省略.........
}
}
while ( ures_hasNext(regionUnknown.getAlias()) ) {
LocalPointer<UnicodeString> regionName (new UnicodeString(ures_getNextUnicodeString(regionUnknown.getAlias(),NULL,&status),status));
allRegions->addElement(regionName.orphan(),status);
}
while ( ures_hasNext(worldContainment.getAlias()) ) {
UnicodeString *continentName = new UnicodeString(ures_getNextUnicodeString(worldContainment.getAlias(),NULL,&status));
continents->addElement(continentName,status);
}
while ( ures_hasNext(groupingContainment.getAlias()) ) {
UnicodeString *groupingName = new UnicodeString(ures_getNextUnicodeString(groupingContainment.getAlias(),NULL,&status));
groupings->addElement(groupingName,status);
}
for ( int32_t i = 0 ; i < allRegions->size() ; i++ ) {
LocalPointer<Region> r(new Region(), status);
if ( U_FAILURE(status) ) {
return;
}
UnicodeString *regionName = (UnicodeString *)allRegions->elementAt(i);
r->idStr = *regionName;
r->idStr.extract(0,r->idStr.length(),r->id,sizeof(r->id),US_INV);
r->type = URGN_TERRITORY; // Only temporary - figure out the real type later once the aliases are known.
Formattable result;
UErrorCode ps = U_ZERO_ERROR;
df->parse(r->idStr,result,ps);
if ( U_SUCCESS(ps) ) {
r->code = result.getLong(); // Convert string to number
uhash_iput(newNumericCodeMap.getAlias(),r->code,(void *)(r.getAlias()),&status);
r->type = URGN_SUBCONTINENT;
} else {
r->code = -1;
}
void* idStrAlias = (void*)&(r->idStr); // about to orphan 'r'. Save this off.
uhash_put(newRegionIDMap.getAlias(),idStrAlias,(void *)(r.orphan()),&status); // regionIDMap takes ownership
}
// Process the territory aliases
while ( ures_hasNext(territoryAlias.getAlias()) ) {
LocalUResourceBundlePointer res(ures_getNextResource(territoryAlias.getAlias(),NULL,&status));
const char *aliasFrom = ures_getKey(res.getAlias());
LocalPointer<UnicodeString> aliasFromStr(new UnicodeString(aliasFrom, -1, US_INV), status);
UnicodeString aliasTo = ures_getUnicodeStringByKey(res.getAlias(),"replacement",&status);
res.adoptInstead(NULL);
const Region *aliasToRegion = (Region *) uhash_get(newRegionIDMap.getAlias(),&aliasTo);
Region *aliasFromRegion = (Region *)uhash_get(newRegionIDMap.getAlias(),aliasFromStr.getAlias());
if ( aliasToRegion != NULL && aliasFromRegion == NULL ) { // This is just an alias from some string to a region
uhash_put(newRegionAliases.getAlias(),(void *)aliasFromStr.orphan(), (void *)aliasToRegion,&status);
} else {
if ( aliasFromRegion == NULL ) { // Deprecated region code not in the master codes list - so need to create a deprecated region for it.
LocalPointer<Region> newRgn(new Region, status);
if ( U_SUCCESS(status) ) {
aliasFromRegion = newRgn.orphan();
} else {
return; // error out
}
aliasFromRegion->idStr.setTo(*aliasFromStr);
aliasFromRegion->idStr.extract(0,aliasFromRegion->idStr.length(),aliasFromRegion->id,sizeof(aliasFromRegion->id),US_INV);
示例14: workText
UBool
NumeratorSubstitution::doParse(const UnicodeString& text,
ParsePosition& parsePosition,
double baseValue,
double upperBound,
UBool /*lenientParse*/,
Formattable& result) const
{
// we don't have to do anything special to do the parsing here,
// but we have to turn lenient parsing off-- if we leave it on,
// it SERIOUSLY messes up the algorithm
// if withZeros is true, we need to count the zeros
// and use that to adjust the parse result
UErrorCode status = U_ZERO_ERROR;
int32_t zeroCount = 0;
UnicodeString workText(text);
if (withZeros) {
ParsePosition workPos(1);
Formattable temp;
while (workText.length() > 0 && workPos.getIndex() != 0) {
workPos.setIndex(0);
getRuleSet()->parse(workText, workPos, 1, temp); // parse zero or nothing at all
if (workPos.getIndex() == 0) {
// we failed, either there were no more zeros, or the number was formatted with digits
// either way, we're done
break;
}
++zeroCount;
parsePosition.setIndex(parsePosition.getIndex() + workPos.getIndex());
workText.remove(0, workPos.getIndex());
while (workText.length() > 0 && workText.charAt(0) == gSpace) {
workText.remove(0, 1);
parsePosition.setIndex(parsePosition.getIndex() + 1);
}
}
workText = text;
workText.remove(0, (int32_t)parsePosition.getIndex());
parsePosition.setIndex(0);
}
// we've parsed off the zeros, now let's parse the rest from our current position
NFSubstitution::doParse(workText, parsePosition, withZeros ? 1 : baseValue, upperBound, FALSE, result);
if (withZeros) {
// any base value will do in this case. is there a way to
// force this to not bother trying all the base values?
// compute the 'effective' base and prescale the value down
int64_t n = result.getLong(status); // force conversion!
int64_t d = 1;
int32_t pow = 0;
while (d <= n) {
d *= 10;
++pow;
}
// now add the zeros
while (zeroCount > 0) {
d *= 10;
--zeroCount;
}
// d is now our true denominator
result.setDouble((double)n/(double)d);
}
return TRUE;
}
示例15: doParse
UBool
FractionalPartSubstitution::doParse(const UnicodeString& text,
ParsePosition& parsePosition,
double baseValue,
double /*upperBound*/,
UBool lenientParse,
Formattable& resVal) const
{
// if we're not in byDigits mode, we can just use the inherited
// doParse()
if (!byDigits) {
return NFSubstitution::doParse(text, parsePosition, baseValue, 0, lenientParse, resVal);
// if we ARE in byDigits mode, parse the text one digit at a time
// using this substitution's owning rule set (we do this by setting
// upperBound to 10 when calling doParse() ) until we reach
// nonmatching text
} else {
UnicodeString workText(text);
ParsePosition workPos(1);
double result = 0;
int32_t digit;
// double p10 = 0.1;
DigitList dl;
NumberFormat* fmt = NULL;
while (workText.length() > 0 && workPos.getIndex() != 0) {
workPos.setIndex(0);
Formattable temp;
getRuleSet()->parse(workText, workPos, 10, temp);
UErrorCode status = U_ZERO_ERROR;
digit = temp.getLong(status);
// digit = temp.getType() == Formattable::kLong ?
// temp.getLong() :
// (int32_t)temp.getDouble();
if (lenientParse && workPos.getIndex() == 0) {
if (!fmt) {
status = U_ZERO_ERROR;
fmt = NumberFormat::createInstance(status);
if (U_FAILURE(status)) {
delete fmt;
fmt = NULL;
}
}
if (fmt) {
fmt->parse(workText, temp, workPos);
digit = temp.getLong(status);
}
}
if (workPos.getIndex() != 0) {
dl.append((char)('0' + digit));
// result += digit * p10;
// p10 /= 10;
parsePosition.setIndex(parsePosition.getIndex() + workPos.getIndex());
workText.removeBetween(0, workPos.getIndex());
while (workText.length() > 0 && workText.charAt(0) == gSpace) {
workText.removeBetween(0, 1);
parsePosition.setIndex(parsePosition.getIndex() + 1);
}
}
}
delete fmt;
result = dl.fCount == 0 ? 0 : dl.getDouble();
result = composeRuleValue(result, baseValue);
resVal.setDouble(result);
return TRUE;
}
}