本文整理汇总了C++中NumberFormat::setParseIntegerOnly方法的典型用法代码示例。如果您正苦于以下问题:C++ NumberFormat::setParseIntegerOnly方法的具体用法?C++ NumberFormat::setParseIntegerOnly怎么用?C++ NumberFormat::setParseIntegerOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumberFormat
的用法示例。
在下文中一共展示了NumberFormat::setParseIntegerOnly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pos
UBool
TimeZone::parseCustomID(const UnicodeString& id, int32_t& sign,
int32_t& hour, int32_t& min, int32_t& sec) {
static const int32_t kParseFailed = -99999;
NumberFormat* numberFormat = 0;
UnicodeString idUppercase = id;
idUppercase.toUpper();
if (id.length() > GMT_ID_LENGTH &&
idUppercase.startsWith(GMT_ID))
{
ParsePosition pos(GMT_ID_LENGTH);
sign = 1;
hour = 0;
min = 0;
sec = 0;
if (id[pos.getIndex()] == MINUS /*'-'*/) {
sign = -1;
} else if (id[pos.getIndex()] != PLUS /*'+'*/) {
return FALSE;
}
pos.setIndex(pos.getIndex() + 1);
UErrorCode success = U_ZERO_ERROR;
numberFormat = NumberFormat::createInstance(success);
if(U_FAILURE(success)){
return FALSE;
}
numberFormat->setParseIntegerOnly(TRUE);
// Look for either hh:mm, hhmm, or hh
int32_t start = pos.getIndex();
Formattable n(kParseFailed);
numberFormat->parse(id, n, pos);
if (pos.getIndex() == start) {
delete numberFormat;
return FALSE;
}
hour = n.getLong();
if (pos.getIndex() < id.length()) {
if (pos.getIndex() - start > 2
|| id[pos.getIndex()] != COLON) {
delete numberFormat;
return FALSE;
}
// hh:mm
pos.setIndex(pos.getIndex() + 1);
int32_t oldPos = pos.getIndex();
n.setLong(kParseFailed);
numberFormat->parse(id, n, pos);
if ((pos.getIndex() - oldPos) != 2) {
// must be 2 digits
delete numberFormat;
return FALSE;
}
min = n.getLong();
if (pos.getIndex() < id.length()) {
if (id[pos.getIndex()] != COLON) {
delete numberFormat;
return FALSE;
}
// [:ss]
pos.setIndex(pos.getIndex() + 1);
oldPos = pos.getIndex();
n.setLong(kParseFailed);
numberFormat->parse(id, n, pos);
if (pos.getIndex() != id.length()
|| (pos.getIndex() - oldPos) != 2) {
delete numberFormat;
return FALSE;
}
sec = n.getLong();
}
} else {
// Supported formats are below -
//
// HHmmss
// Hmmss
// HHmm
// Hmm
// HH
// H
int32_t length = pos.getIndex() - start;
if (length <= 0 || 6 < length) {
// invalid length
delete numberFormat;
return FALSE;
}
switch (length) {
case 1:
case 2:
// already set to hour
break;
case 3:
case 4:
min = hour % 100;
//.........这里部分代码省略.........
示例2: testAPI
//.........这里部分代码省略.........
}
// ======= Test parse()
if (fr != NULL)
{
logln("Testing parse()");
double d = -10456.0037;
UnicodeString text("-10,456.0037");
Formattable result1, result2, result3;
ParsePosition pos(0), pos01(0);
fr->parseObject(text, result1, pos);
if(result1.getType() != Formattable::kDouble && result1.getDouble() != d) {
errln("ERROR: Roundtrip failed (via parse()) for " + text);
}
logln(text + " parsed into " + (int32_t) result1.getDouble());
fr->parse(text, result2, pos01);
if(result2.getType() != Formattable::kDouble && result2.getDouble() != d) {
errln("ERROR: Roundtrip failed (via parse()) for " + text);
}
logln(text + " parsed into " + (int32_t) result2.getDouble());
status = U_ZERO_ERROR;
fr->parse(text, result3, status);
if(U_FAILURE(status)) {
errln("ERROR: parse() failed");
}
if(result3.getType() != Formattable::kDouble && result3.getDouble() != d) {
errln("ERROR: Roundtrip failed (via parse()) for " + text);
}
logln(text + " parsed into " + (int32_t) result3.getDouble());
}
// ======= Test getters and setters
if (fr != NULL && def != NULL)
{
logln("Testing getters and setters");
int32_t count = 0;
const Locale *locales = NumberFormat::getAvailableLocales(count);
logln((UnicodeString) "Got " + count + " locales" );
for(int32_t i = 0; i < count; i++) {
UnicodeString name(locales[i].getName(),"");
logln(name);
}
fr->setParseIntegerOnly( def->isParseIntegerOnly() );
if(fr->isParseIntegerOnly() != def->isParseIntegerOnly() ) {
errln("ERROR: setParseIntegerOnly() failed");
}
fr->setGroupingUsed( def->isGroupingUsed() );
if(fr->isGroupingUsed() != def->isGroupingUsed() ) {
errln("ERROR: setGroupingUsed() failed");
}
fr->setMaximumIntegerDigits( def->getMaximumIntegerDigits() );
if(fr->getMaximumIntegerDigits() != def->getMaximumIntegerDigits() ) {
errln("ERROR: setMaximumIntegerDigits() failed");
}
fr->setMinimumIntegerDigits( def->getMinimumIntegerDigits() );
if(fr->getMinimumIntegerDigits() != def->getMinimumIntegerDigits() ) {
errln("ERROR: setMinimumIntegerDigits() failed");
}
fr->setMaximumFractionDigits( def->getMaximumFractionDigits() );
if(fr->getMaximumFractionDigits() != def->getMaximumFractionDigits() ) {
errln("ERROR: setMaximumFractionDigits() failed");
}
fr->setMinimumFractionDigits( def->getMinimumFractionDigits() );
if(fr->getMinimumFractionDigits() != def->getMinimumFractionDigits() ) {
errln("ERROR: setMinimumFractionDigits() failed");
}
}
// ======= Test getStaticClassID()
logln("Testing getStaticClassID()");
status = U_ZERO_ERROR;
NumberFormat *test = new DecimalFormat(status);
if(U_FAILURE(status)) {
errln("ERROR: Couldn't create a NumberFormat");
}
if(test->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
errln("ERROR: getDynamicClassID() didn't return the expected value");
}
delete test;
delete def;
delete fr;
delete cur;
delete cur_fr;
delete per;
delete per_fr;
}
示例3: pos
/**
* Parse a custom time zone identifier and return a corresponding zone.
* @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
* GMT[+-]hh.
* @return a newly created SimpleTimeZone with the given offset and
* no Daylight Savings Time, or null if the id cannot be parsed.
*/
TimeZone*
TimeZone::createCustomTimeZone(const UnicodeString& id)
{
static const int32_t kParseFailed = -99999;
NumberFormat* numberFormat = 0;
UnicodeString idUppercase = id;
idUppercase.toUpper();
if (id.length() > GMT_ID_LENGTH &&
idUppercase.startsWith(GMT_ID))
{
ParsePosition pos(GMT_ID_LENGTH);
UBool negative = FALSE;
int32_t offset;
if (id[pos.getIndex()] == 0x002D /*'-'*/)
negative = TRUE;
else if (id[pos.getIndex()] != 0x002B /*'+'*/)
return 0;
pos.setIndex(pos.getIndex() + 1);
UErrorCode success = U_ZERO_ERROR;
numberFormat = NumberFormat::createInstance(success);
numberFormat->setParseIntegerOnly(TRUE);
// Look for either hh:mm, hhmm, or hh
int32_t start = pos.getIndex();
Formattable n(kParseFailed);
numberFormat->parse(id, n, pos);
if (pos.getIndex() == start) {
delete numberFormat;
return 0;
}
offset = n.getLong();
if (pos.getIndex() < id.length() &&
id[pos.getIndex()] == 0x003A /*':'*/)
{
// hh:mm
offset *= 60;
pos.setIndex(pos.getIndex() + 1);
int32_t oldPos = pos.getIndex();
n.setLong(kParseFailed);
numberFormat->parse(id, n, pos);
if (pos.getIndex() == oldPos) {
delete numberFormat;
return 0;
}
offset += n.getLong();
}
else
{
// hhmm or hh
// Be strict about interpreting something as hh; it must be
// an offset < 30, and it must be one or two digits. Thus
// 0010 is interpreted as 00:10, but 10 is interpreted as
// 10:00.
if (offset < 30 && (pos.getIndex() - start) <= 2)
offset *= 60; // hh, from 00 to 29; 30 is 00:30
else
offset = offset % 100 + offset / 100 * 60; // hhmm
}
if(negative)
offset = -offset;
delete numberFormat;
return new SimpleTimeZone(offset * 60000, CUSTOM_ID);
}
return 0;
}