mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-05 21:45:37 +00:00
ICU-5794 Various fixes for the following items.
1) Pass the locale on for the PluralFormat constructor 2) Perform normal ICU error code handling so that parse errors aren't discarded. 3) Remove more C++ static initialization. 4) Remove spaces from test names so that they can be called from the command line. 5) Fix various compiler warnings. X-SVN-Rev: 23141
This commit is contained in:
parent
6261370a47
commit
8081ce1d2b
8 changed files with 347 additions and 396 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1997-2006, International Business Machines Corporation and *
|
||||
* Copyright (C) 1997-2007, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
|
@ -187,12 +187,12 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status,
|
|||
UChar ucc[4]={0}; //Currency Codes are always 3 chars long
|
||||
int32_t uccLen = 4;
|
||||
const char* locName = loc.getName();
|
||||
uccLen = ucurr_forLocale(locName, ucc, uccLen, &status);
|
||||
if(U_SUCCESS(status) && uccLen > 0) {
|
||||
UErrorCode localStatus = U_ZERO_ERROR;
|
||||
uccLen = ucurr_forLocale(locName, ucc, uccLen, &localStatus);
|
||||
if(U_SUCCESS(localStatus) && uccLen > 0) {
|
||||
char cc[4]={0};
|
||||
u_UCharsToChars(ucc, cc, uccLen);
|
||||
/* An explicit currency was requested */
|
||||
UErrorCode localStatus = U_ZERO_ERROR;
|
||||
UResourceBundle *currency = ures_getByKeyWithFallback(resource, "Currencies", NULL, &localStatus);
|
||||
currency = ures_getByKeyWithFallback(currency, cc, currency, &localStatus);
|
||||
if(U_SUCCESS(localStatus) && ures_getSize(currency)>2) { // the length is 3 if more data is present
|
||||
|
@ -211,10 +211,8 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status,
|
|||
ures_close(currency);
|
||||
/* else An explicit currency was requested and is unknown or locale data is malformed. */
|
||||
/* ucurr_* API will get the correct value later on. */
|
||||
}else{
|
||||
// ignore the error if no currency
|
||||
status = U_ZERO_ERROR;
|
||||
}
|
||||
// else ignore the error if no currency
|
||||
}
|
||||
ures_close(resource);
|
||||
ures_close(numberElementsRes);
|
||||
|
|
|
@ -198,17 +198,17 @@ MessageFormat::MessageFormat(const UnicodeString& pattern,
|
|||
: fLocale(Locale::getDefault()), // Uses the default locale
|
||||
formatAliases(NULL),
|
||||
formatAliasesCapacity(0),
|
||||
idStart(UCHAR_ID_START),
|
||||
idContinue(UCHAR_ID_CONTINUE),
|
||||
subformats(NULL),
|
||||
subformatCount(0),
|
||||
subformatCapacity(0),
|
||||
argTypes(NULL),
|
||||
argTypeCount(0),
|
||||
argTypeCapacity(0),
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL),
|
||||
isArgNumeric(TRUE),
|
||||
idStart(UCHAR_ID_START),
|
||||
idContinue(UCHAR_ID_CONTINUE)
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL)
|
||||
{
|
||||
if (!allocateSubformats(DEFAULT_INITIAL_CAPACITY) ||
|
||||
!allocateArgTypes(DEFAULT_INITIAL_CAPACITY)) {
|
||||
|
@ -225,17 +225,17 @@ MessageFormat::MessageFormat(const UnicodeString& pattern,
|
|||
: fLocale(newLocale),
|
||||
formatAliases(NULL),
|
||||
formatAliasesCapacity(0),
|
||||
idStart(UCHAR_ID_START),
|
||||
idContinue(UCHAR_ID_CONTINUE),
|
||||
subformats(NULL),
|
||||
subformatCount(0),
|
||||
subformatCapacity(0),
|
||||
argTypes(NULL),
|
||||
argTypeCount(0),
|
||||
argTypeCapacity(0),
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL),
|
||||
isArgNumeric(TRUE),
|
||||
idStart(UCHAR_ID_START),
|
||||
idContinue(UCHAR_ID_CONTINUE)
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL)
|
||||
{
|
||||
if (!allocateSubformats(DEFAULT_INITIAL_CAPACITY) ||
|
||||
!allocateArgTypes(DEFAULT_INITIAL_CAPACITY)) {
|
||||
|
@ -253,17 +253,17 @@ MessageFormat::MessageFormat(const UnicodeString& pattern,
|
|||
: fLocale(newLocale),
|
||||
formatAliases(NULL),
|
||||
formatAliasesCapacity(0),
|
||||
idStart(UCHAR_ID_START),
|
||||
idContinue(UCHAR_ID_CONTINUE),
|
||||
subformats(NULL),
|
||||
subformatCount(0),
|
||||
subformatCapacity(0),
|
||||
argTypes(NULL),
|
||||
argTypeCount(0),
|
||||
argTypeCapacity(0),
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL),
|
||||
isArgNumeric(TRUE),
|
||||
idStart(UCHAR_ID_START),
|
||||
idContinue(UCHAR_ID_CONTINUE)
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL)
|
||||
{
|
||||
if (!allocateSubformats(DEFAULT_INITIAL_CAPACITY) ||
|
||||
!allocateArgTypes(DEFAULT_INITIAL_CAPACITY)) {
|
||||
|
@ -278,16 +278,17 @@ MessageFormat::MessageFormat(const MessageFormat& that)
|
|||
: Format(that),
|
||||
formatAliases(NULL),
|
||||
formatAliasesCapacity(0),
|
||||
idStart(UCHAR_ID_START),
|
||||
idContinue(UCHAR_ID_CONTINUE),
|
||||
subformats(NULL),
|
||||
subformatCount(0),
|
||||
subformatCapacity(0),
|
||||
argTypes(NULL),
|
||||
argTypeCount(0),
|
||||
argTypeCapacity(0),
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL),
|
||||
isArgNumeric(TRUE),
|
||||
idStart(UCHAR_ID_START)
|
||||
defaultNumberFormat(NULL),
|
||||
defaultDateFormat(NULL)
|
||||
{
|
||||
*this = that;
|
||||
}
|
||||
|
@ -1523,6 +1524,7 @@ MessageFormat::makeFormat(int32_t formatNumber,
|
|||
fmt = makeRBNF(URBNF_DURATION, fLocale, segments[3], ec);
|
||||
break;
|
||||
case 8: // plural
|
||||
argType = Formattable::kDouble;
|
||||
quotedPattern = segments[3];
|
||||
for (int32_t i = 0; i < quotedPattern.length(); ++i) {
|
||||
UChar ch = quotedPattern.charAt(i);
|
||||
|
@ -1717,7 +1719,7 @@ MessageFormat::isLegalArgName(const UnicodeString& argName) const {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
FormatNameEnumeration::FormatNameEnumeration(UVector *fNameList, UErrorCode& status) {
|
||||
FormatNameEnumeration::FormatNameEnumeration(UVector *fNameList, UErrorCode& /*status*/) {
|
||||
pos=0;
|
||||
fFormatNames = fNameList;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ deleteHashStrings(void *obj) {
|
|||
U_CDECL_END
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralFormat);
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralFormat)
|
||||
|
||||
#define MAX_KEYWORD_SIZE 30
|
||||
|
||||
|
@ -46,7 +46,7 @@ PluralFormat::PluralFormat(const PluralRules& rules, UErrorCode& status) {
|
|||
}
|
||||
|
||||
PluralFormat::PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status) {
|
||||
init(&rules, Locale::getDefault(), status);
|
||||
init(&rules, locale, status);
|
||||
}
|
||||
|
||||
PluralFormat::PluralFormat(const UnicodeString& pattern, UErrorCode& status) {
|
||||
|
@ -69,7 +69,7 @@ PluralFormat::PluralFormat(const Locale& locale, const PluralRules& rules, const
|
|||
applyPattern(pattern, status);
|
||||
}
|
||||
|
||||
PluralFormat::PluralFormat(const PluralFormat& other) {
|
||||
PluralFormat::PluralFormat(const PluralFormat& other) : Format(other) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
locale = other.locale;
|
||||
pluralRules = other.pluralRules->clone();
|
||||
|
@ -87,7 +87,6 @@ PluralFormat::~PluralFormat() {
|
|||
|
||||
void
|
||||
PluralFormat::init(const PluralRules* rules, const Locale& curLocale, UErrorCode& status) {
|
||||
status = U_ZERO_ERROR;
|
||||
locale = curLocale;
|
||||
if ( rules==NULL) {
|
||||
pluralRules = PluralRules::forLocale(locale, status);
|
||||
|
@ -258,7 +257,7 @@ UnicodeString&
|
|||
PluralFormat::format(int32_t number,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos,
|
||||
UErrorCode& status) const{
|
||||
UErrorCode& status) const {
|
||||
|
||||
if (fParsedValuesHash==NULL) {
|
||||
if ( replacedNumberFormat== NULL ) {
|
||||
|
@ -348,7 +347,6 @@ PluralFormat::setNumberFormat(const NumberFormat* format, UErrorCode& status) {
|
|||
// TODO: The copy constructor and assignment op of NumberFormat class are protected.
|
||||
// create a pointer as the workaround.
|
||||
replacedNumberFormat = (NumberFormat *)format;
|
||||
return;
|
||||
}
|
||||
|
||||
Format*
|
||||
|
|
|
@ -112,7 +112,7 @@ static const UChar PK_AND[]={LOW_A,LOW_N,LOW_D,0};
|
|||
static const UChar PK_OR[]={LOW_O,LOW_R,0};
|
||||
static const UChar PK_VAR_N[]={LOW_N,0};
|
||||
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralRules);
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralRules)
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralKeywordEnumeration)
|
||||
|
||||
PluralRules::PluralRules(UErrorCode& status) {
|
||||
|
@ -125,7 +125,9 @@ PluralRules::PluralRules(UErrorCode& status) {
|
|||
}
|
||||
}
|
||||
|
||||
PluralRules::PluralRules(const PluralRules& other) {
|
||||
PluralRules::PluralRules(const PluralRules& other)
|
||||
: UObject(other)
|
||||
{
|
||||
*this=other;
|
||||
}
|
||||
|
||||
|
@ -141,7 +143,7 @@ PluralRules::clone() const {
|
|||
}
|
||||
|
||||
PluralRules&
|
||||
PluralRules:: operator=(const PluralRules& other) {
|
||||
PluralRules::operator=(const PluralRules& other) {
|
||||
fLocaleStringsHash=other.fLocaleStringsHash;
|
||||
rules = new RuleChain(*other.rules);
|
||||
parser = new RuleParser();
|
||||
|
@ -155,9 +157,9 @@ PluralRules::createRules(const UnicodeString& description, UErrorCode& status) {
|
|||
|
||||
PluralRules *newRules = new PluralRules(status);
|
||||
if ( (newRules != NULL)&& U_SUCCESS(status) ) {
|
||||
status = newRules->parseDescription((UnicodeString &)description, rules);
|
||||
newRules->parseDescription((UnicodeString &)description, rules, status);
|
||||
if (U_SUCCESS(status)) {
|
||||
newRules->addRules(rules, status);
|
||||
newRules->addRules(rules, status);
|
||||
}
|
||||
}
|
||||
if (U_FAILURE(status)) {
|
||||
|
@ -179,6 +181,10 @@ PluralRules::forLocale(const Locale& locale, UErrorCode& status) {
|
|||
RuleChain *locRules;
|
||||
|
||||
PluralRules *newRules = new PluralRules(status);
|
||||
if (U_FAILURE(status)) {
|
||||
delete newRules;
|
||||
return NULL;
|
||||
}
|
||||
UnicodeString localeName=UnicodeString(locale.getName());
|
||||
locRules = (RuleChain *) (fPluralRuleLocaleHash->get(localeName));
|
||||
if ( locRules==NULL ) {
|
||||
|
@ -298,7 +304,6 @@ PluralRules::getRuleData(UErrorCode& status) {
|
|||
UnicodeString localeName;
|
||||
int32_t i;
|
||||
UChar cSlash = (UChar)0x002F;
|
||||
status=U_ZERO_ERROR;
|
||||
|
||||
i=0;
|
||||
while ( i<NUMBER_PLURAL_RULES && U_SUCCESS(status) ) {
|
||||
|
@ -310,7 +315,7 @@ PluralRules::getRuleData(UErrorCode& status) {
|
|||
}
|
||||
ruleData=UnicodeString(pluralRuleData, 0, slashIndex);
|
||||
localeData=UnicodeString(pluralRuleData, slashIndex+1);
|
||||
status = parseDescription(ruleData, rules);
|
||||
parseDescription(ruleData, rules, status);
|
||||
int32_t curIndex=0;
|
||||
while (curIndex < localeData.length() && U_SUCCESS(status)) {
|
||||
getNextLocale(localeData, &curIndex, localeName);
|
||||
|
@ -320,9 +325,9 @@ PluralRules::getRuleData(UErrorCode& status) {
|
|||
}
|
||||
}
|
||||
|
||||
UErrorCode
|
||||
PluralRules::parseDescription(UnicodeString& data, RuleChain& rules) {
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
void
|
||||
PluralRules::parseDescription(UnicodeString& data, RuleChain& rules, UErrorCode &status)
|
||||
{
|
||||
int32_t ruleIndex=0;
|
||||
UnicodeString token;
|
||||
tokenType type;
|
||||
|
@ -333,71 +338,71 @@ PluralRules::parseDescription(UnicodeString& data, RuleChain& rules) {
|
|||
|
||||
UnicodeString ruleData = data.toLower();
|
||||
while (ruleIndex< ruleData.length()) {
|
||||
if ((status=parser->getNextToken(ruleData, &ruleIndex, token, type))!=U_ZERO_ERROR) {
|
||||
return status;
|
||||
parser->getNextToken(ruleData, &ruleIndex, token, type, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
if ((status=parser->checkSyntax(prevType, type))!=U_ZERO_ERROR) {
|
||||
return status;
|
||||
parser->checkSyntax(prevType, type, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case tAnd:
|
||||
curAndConstraint = curAndConstraint->add();
|
||||
break;
|
||||
case tOr:
|
||||
orNode=rules.ruleHeader;
|
||||
while (orNode->next != NULL) {
|
||||
orNode = orNode->next;
|
||||
}
|
||||
orNode->next= new OrConstraint();
|
||||
orNode=orNode->next;
|
||||
orNode->next=NULL;
|
||||
curAndConstraint = orNode->add();
|
||||
break;
|
||||
case tIs:
|
||||
curAndConstraint->rangeHigh=-1;
|
||||
break;
|
||||
case tNot:
|
||||
curAndConstraint->notIn=TRUE;
|
||||
break;
|
||||
case tIn:
|
||||
curAndConstraint->rangeHigh=PLURAL_RANGE_HIGH;
|
||||
break;
|
||||
case tNumber:
|
||||
if ( (curAndConstraint->op==AndConstraint::MOD)&&
|
||||
(curAndConstraint->opNum == -1 ) ) {
|
||||
curAndConstraint->opNum=getNumberValue(token);
|
||||
case tAnd:
|
||||
curAndConstraint = curAndConstraint->add();
|
||||
break;
|
||||
case tOr:
|
||||
orNode=rules.ruleHeader;
|
||||
while (orNode->next != NULL) {
|
||||
orNode = orNode->next;
|
||||
}
|
||||
orNode->next= new OrConstraint();
|
||||
orNode=orNode->next;
|
||||
orNode->next=NULL;
|
||||
curAndConstraint = orNode->add();
|
||||
break;
|
||||
case tIs:
|
||||
curAndConstraint->rangeHigh=-1;
|
||||
break;
|
||||
case tNot:
|
||||
curAndConstraint->notIn=TRUE;
|
||||
break;
|
||||
case tIn:
|
||||
curAndConstraint->rangeHigh=PLURAL_RANGE_HIGH;
|
||||
break;
|
||||
case tNumber:
|
||||
if ( (curAndConstraint->op==AndConstraint::MOD)&&
|
||||
(curAndConstraint->opNum == -1 ) ) {
|
||||
curAndConstraint->opNum=getNumberValue(token);
|
||||
}
|
||||
else {
|
||||
if (curAndConstraint->rangeLow == -1) {
|
||||
curAndConstraint->rangeLow=getNumberValue(token);
|
||||
}
|
||||
else {
|
||||
if (curAndConstraint->rangeLow == -1) {
|
||||
curAndConstraint->rangeLow=getNumberValue(token);
|
||||
}
|
||||
else {
|
||||
curAndConstraint->rangeHigh=getNumberValue(token);
|
||||
}
|
||||
curAndConstraint->rangeHigh=getNumberValue(token);
|
||||
}
|
||||
break;
|
||||
case tMod:
|
||||
curAndConstraint->op=AndConstraint::MOD;
|
||||
break;
|
||||
case tKeyword:
|
||||
if (ruleChain==NULL) {
|
||||
ruleChain = &rules;
|
||||
}
|
||||
break;
|
||||
case tMod:
|
||||
curAndConstraint->op=AndConstraint::MOD;
|
||||
break;
|
||||
case tKeyword:
|
||||
if (ruleChain==NULL) {
|
||||
ruleChain = &rules;
|
||||
}
|
||||
else {
|
||||
while (ruleChain->next!=NULL){
|
||||
ruleChain=ruleChain->next;
|
||||
}
|
||||
else {
|
||||
while (ruleChain->next!=NULL){
|
||||
ruleChain=ruleChain->next;
|
||||
}
|
||||
ruleChain=ruleChain->next=new RuleChain();
|
||||
}
|
||||
orNode = ruleChain->ruleHeader = new OrConstraint();
|
||||
curAndConstraint = orNode->add();
|
||||
ruleChain->keyword = token;
|
||||
break;
|
||||
ruleChain=ruleChain->next=new RuleChain();
|
||||
}
|
||||
orNode = ruleChain->ruleHeader = new OrConstraint();
|
||||
curAndConstraint = orNode->add();
|
||||
ruleChain->keyword = token;
|
||||
break;
|
||||
}
|
||||
prevType=type;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t
|
||||
|
@ -516,7 +521,7 @@ AndConstraint::~AndConstraint() {
|
|||
if (next!=NULL) {
|
||||
delete next;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
UBool
|
||||
|
@ -844,90 +849,79 @@ RuleParser::~RuleParser() {
|
|||
delete idContinueFilter;
|
||||
}
|
||||
|
||||
UErrorCode
|
||||
RuleParser::checkSyntax(tokenType prevType, tokenType curType ) {
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
|
||||
void
|
||||
RuleParser::checkSyntax(tokenType prevType, tokenType curType, UErrorCode &status)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
switch(prevType) {
|
||||
case none:
|
||||
case tSemiColon:
|
||||
if (curType!=tKeyword) {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
else {
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
case tVariableN :
|
||||
if ( (curType == tIs) || (curType == tMod) || (curType == tIn) || (curType == tNot) ) {
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
else {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
case tZero:
|
||||
case tOne:
|
||||
case tTwo:
|
||||
case tFew:
|
||||
case tMany:
|
||||
case tOther:
|
||||
case tKeyword:
|
||||
if ( curType == tColon ) {
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
else {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
case tColon :
|
||||
if ( curType == tVariableN ) {
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
else {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
case tIs:
|
||||
if ( (curType == tNumber) || (curType == tNot)) {
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
else {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
case tNot:
|
||||
if ((curType == tNumber) || (curType == tIn)){
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
else {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
case tMod:
|
||||
case tDot:
|
||||
case tIn:
|
||||
case tAnd:
|
||||
case tOr:
|
||||
if ( (curType == tNumber) || (curType == tVariableN) ){
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
else {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
case tNumber:
|
||||
if ((curType == tDot) || (curType == tSemiColon) || (curType == tIs) || (curType == tNot) ||
|
||||
(curType == tIn) || (curType == tAnd) || (curType == tOr) ){
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
else {
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
default:
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
case none:
|
||||
case tSemiColon:
|
||||
if (curType!=tKeyword) {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case tVariableN :
|
||||
if (curType != tIs && curType != tMod && curType != tIn && curType != tNot) {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case tZero:
|
||||
case tOne:
|
||||
case tTwo:
|
||||
case tFew:
|
||||
case tMany:
|
||||
case tOther:
|
||||
case tKeyword:
|
||||
if (curType != tColon) {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case tColon :
|
||||
if (curType != tVariableN) {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case tIs:
|
||||
if ( curType != tNumber && curType != tNot) {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case tNot:
|
||||
if (curType != tNumber && curType != tIn) {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case tMod:
|
||||
case tDot:
|
||||
case tIn:
|
||||
case tAnd:
|
||||
case tOr:
|
||||
if (curType != tNumber && curType != tVariableN) {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
case tNumber:
|
||||
if (curType != tDot && curType != tSemiColon && curType != tIs && curType != tNot &&
|
||||
curType != tIn && curType != tAnd && curType != tOr)
|
||||
{
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UErrorCode
|
||||
void
|
||||
RuleParser::getNextToken(const UnicodeString& ruleData,
|
||||
int32_t *ruleIndex,
|
||||
UnicodeString& token,
|
||||
tokenType& type) {
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
tokenType& type,
|
||||
UErrorCode &status)
|
||||
{
|
||||
int32_t curIndex= *ruleIndex;
|
||||
UChar ch;
|
||||
tokenType prevType=none;
|
||||
|
@ -935,77 +929,77 @@ RuleParser::getNextToken(const UnicodeString& ruleData,
|
|||
while (curIndex<ruleData.length()) {
|
||||
ch = ruleData.charAt(curIndex);
|
||||
if ( !inRange(ch, type) ) {
|
||||
return U_ILLEGAL_CHARACTER;
|
||||
status = U_ILLEGAL_CHARACTER;
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case tSpace:
|
||||
if ( *ruleIndex != curIndex ) { // letter
|
||||
case tSpace:
|
||||
if ( *ruleIndex != curIndex ) { // letter
|
||||
token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
|
||||
*ruleIndex=curIndex;
|
||||
type=prevType;
|
||||
getKeyType(token, type, status);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
*ruleIndex=*ruleIndex+1;
|
||||
}
|
||||
break; // consective space
|
||||
case tColon:
|
||||
case tSemiColon:
|
||||
if ( *ruleIndex != curIndex ) {
|
||||
token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
|
||||
*ruleIndex=curIndex;
|
||||
type=prevType;
|
||||
getKeyType(token, type, status);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
*ruleIndex=curIndex+1;
|
||||
return;
|
||||
}
|
||||
case tLetter:
|
||||
if ((type==prevType)||(prevType==none)) {
|
||||
prevType=type;
|
||||
break;
|
||||
}
|
||||
case tNumber:
|
||||
if ((type==prevType)||(prevType==none)) {
|
||||
prevType=type;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
*ruleIndex=curIndex+1;
|
||||
return;
|
||||
}
|
||||
case tDot:
|
||||
if (prevType==none) { // first dot
|
||||
prevType=type;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if ( *ruleIndex != curIndex ) {
|
||||
token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
|
||||
*ruleIndex=curIndex;
|
||||
*ruleIndex=curIndex; // letter
|
||||
type=prevType;
|
||||
status=getKeyType(token, type);
|
||||
return status;
|
||||
}
|
||||
else {
|
||||
*ruleIndex=*ruleIndex+1;
|
||||
}
|
||||
break; // consective space
|
||||
case tColon:
|
||||
case tSemiColon:
|
||||
if ( *ruleIndex != curIndex ) {
|
||||
token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
|
||||
*ruleIndex=curIndex;
|
||||
type=prevType;
|
||||
status=getKeyType(token, type);
|
||||
return status;
|
||||
}
|
||||
else {
|
||||
*ruleIndex=curIndex+1;
|
||||
return status;
|
||||
}
|
||||
case tLetter:
|
||||
if ((type==prevType)||(prevType==none)) {
|
||||
prevType=type;
|
||||
break;
|
||||
getKeyType(token, type, status);
|
||||
return;
|
||||
}
|
||||
case tNumber:
|
||||
if ((type==prevType)||(prevType==none)) {
|
||||
prevType=type;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
*ruleIndex=curIndex+1;
|
||||
return status;
|
||||
}
|
||||
case tDot:
|
||||
if (prevType==none) { // first dot
|
||||
prevType=type;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if ( *ruleIndex != curIndex ) {
|
||||
token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
|
||||
*ruleIndex=curIndex; // letter
|
||||
type=prevType;
|
||||
status=getKeyType(token, type);
|
||||
return status;
|
||||
}
|
||||
else { // two consective dots
|
||||
*ruleIndex=curIndex+2;
|
||||
return status;
|
||||
}
|
||||
else { // two consective dots
|
||||
*ruleIndex=curIndex+2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
curIndex++;
|
||||
}
|
||||
if ( curIndex>=ruleData.length() ) {
|
||||
if ( (type == tLetter)||(type == tNumber) ) {
|
||||
token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
|
||||
status=getKeyType(token, type);
|
||||
getKeyType(token, type, status);
|
||||
}
|
||||
*ruleIndex = ruleData.length();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
UBool
|
||||
|
@ -1023,65 +1017,57 @@ RuleParser::inRange(UChar ch, tokenType& type) {
|
|||
return TRUE;
|
||||
}
|
||||
switch (ch) {
|
||||
case COLON:
|
||||
type = tColon;
|
||||
return TRUE;
|
||||
case SPACE:
|
||||
type = tSpace;
|
||||
return TRUE;
|
||||
case SEMI_COLON:
|
||||
type = tSemiColon;
|
||||
return TRUE;
|
||||
case DOT:
|
||||
type = tDot;
|
||||
return TRUE;
|
||||
default :
|
||||
type = none;
|
||||
return FALSE;
|
||||
case COLON:
|
||||
type = tColon;
|
||||
return TRUE;
|
||||
case SPACE:
|
||||
type = tSpace;
|
||||
return TRUE;
|
||||
case SEMI_COLON:
|
||||
type = tSemiColon;
|
||||
return TRUE;
|
||||
case DOT:
|
||||
type = tDot;
|
||||
return TRUE;
|
||||
default :
|
||||
type = none;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UErrorCode
|
||||
RuleParser::getKeyType(const UnicodeString& token, tokenType& keyType) {
|
||||
void
|
||||
RuleParser::getKeyType(const UnicodeString& token, tokenType& keyType, UErrorCode &status)
|
||||
{
|
||||
if ( keyType==tNumber) {
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
if (token==PK_VAR_N) {
|
||||
else if (token==PK_VAR_N) {
|
||||
keyType = tVariableN;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
if (token==PK_IS) {
|
||||
else if (token==PK_IS) {
|
||||
keyType = tIs;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
if (token==PK_AND) {
|
||||
else if (token==PK_AND) {
|
||||
keyType = tAnd;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
if (token==PK_IN) {
|
||||
else if (token==PK_IN) {
|
||||
keyType = tIn;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
if (token==PK_NOT) {
|
||||
else if (token==PK_NOT) {
|
||||
keyType = tNot;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
if (token==PK_MOD) {
|
||||
else if (token==PK_MOD) {
|
||||
keyType = tMod;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
if (token==PK_OR) {
|
||||
else if (token==PK_OR) {
|
||||
keyType = tOr;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
|
||||
if ( isValidKeyword(token) ) {
|
||||
else if ( isValidKeyword(token) ) {
|
||||
keyType = tKeyword;
|
||||
return U_ZERO_ERROR;
|
||||
}
|
||||
|
||||
return U_UNEXPECTED_TOKEN;
|
||||
else {
|
||||
status = U_UNEXPECTED_TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
UBool
|
||||
|
|
|
@ -98,7 +98,7 @@ typedef enum PluralKey {
|
|||
pFew,
|
||||
pMany,
|
||||
pOther,
|
||||
pLast,
|
||||
pLast
|
||||
}PluralKey;
|
||||
|
||||
typedef enum tokenType {
|
||||
|
@ -126,21 +126,21 @@ typedef enum tokenType {
|
|||
tVariableN,
|
||||
tIs,
|
||||
tLeftBrace,
|
||||
tRightBrace,
|
||||
tRightBrace
|
||||
}tokenType;
|
||||
|
||||
class RuleParser : public UMemory {
|
||||
public:
|
||||
RuleParser();
|
||||
virtual ~RuleParser();
|
||||
UErrorCode getNextToken(const UnicodeString& ruleData, int32_t *ruleIndex, UnicodeString& token,
|
||||
tokenType& type);
|
||||
UErrorCode checkSyntax(tokenType prevType, tokenType curType);
|
||||
void getNextToken(const UnicodeString& ruleData, int32_t *ruleIndex, UnicodeString& token,
|
||||
tokenType& type, UErrorCode &status);
|
||||
void checkSyntax(tokenType prevType, tokenType curType, UErrorCode &status);
|
||||
private:
|
||||
UnicodeSet *idStartFilter;
|
||||
UnicodeSet *idContinueFilter;
|
||||
|
||||
UErrorCode getKeyType(const UnicodeString& token, tokenType& type);
|
||||
void getKeyType(const UnicodeString& token, tokenType& type, UErrorCode &status);
|
||||
UBool inRange(UChar ch, tokenType& type);
|
||||
UBool isValidKeyword(const UnicodeString& token);
|
||||
};
|
||||
|
@ -149,7 +149,7 @@ class AndConstraint : public UMemory {
|
|||
public:
|
||||
typedef enum RuleOp {
|
||||
NONE,
|
||||
MOD,
|
||||
MOD
|
||||
} RuleOp;
|
||||
RuleOp op;
|
||||
int32_t opNum;
|
||||
|
|
|
@ -246,7 +246,7 @@ private:
|
|||
PluralRules(); // default constructor not implemented
|
||||
void getRuleData(UErrorCode& status);
|
||||
int32_t getRepeatLimit() const;
|
||||
UErrorCode parseDescription(UnicodeString& ruleData, RuleChain& rules);
|
||||
void parseDescription(UnicodeString& ruleData, RuleChain& rules, UErrorCode &status);
|
||||
void getNextLocale(const UnicodeString& localeData, int32_t* curIndex, UnicodeString& localeName);
|
||||
void addRules(RuleChain& rules, UErrorCode& err);
|
||||
void addRules(const UnicodeString& localeName, RuleChain& rules, UBool addToHash, UErrorCode& err);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2006, International Business Machines Corporation and
|
||||
* Copyright (c) 2007-2007, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
|
@ -16,55 +15,11 @@
|
|||
#include "unicode/plurfmt.h"
|
||||
|
||||
|
||||
#if defined( U_DEBUG_PLURFMT )
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
const UnicodeString oddAndEvenRule = UNICODE_STRING_SIMPLE("odd: n mod 2 is 1");
|
||||
#define PLURAL_PATTERN_DATA 4
|
||||
#define PLURAL_TEST_ARRAY_SIZE 256
|
||||
|
||||
const UnicodeString patternTestData[PLURAL_PATTERN_DATA] = {
|
||||
UNICODE_STRING_SIMPLE("odd {# is odd.} other{# is even.}"),
|
||||
UNICODE_STRING_SIMPLE("other{# is odd or even.}"),
|
||||
UNICODE_STRING_SIMPLE("odd{The number {0, number, #.#0} is odd.}other{The number {0, number, #.#0} is even.}"),
|
||||
UNICODE_STRING_SIMPLE("odd{The number {#} is odd.}other{The number {#} is even.}"),
|
||||
};
|
||||
|
||||
const UnicodeString patternOddTestResult[PLURAL_PATTERN_DATA] = {
|
||||
UNICODE_STRING_SIMPLE(" is odd."),
|
||||
UNICODE_STRING_SIMPLE(" is odd or even."),
|
||||
UNICODE_STRING_SIMPLE("The number {0, number, #.#0} is odd."),
|
||||
UNICODE_STRING_SIMPLE("The number {#} is odd."),
|
||||
};
|
||||
|
||||
const UnicodeString patternEvenTestResult[PLURAL_PATTERN_DATA] = {
|
||||
UNICODE_STRING_SIMPLE(" is even."),
|
||||
UNICODE_STRING_SIMPLE(" is odd or even."),
|
||||
UNICODE_STRING_SIMPLE("The number {0, number, #.#0} is even."),
|
||||
UNICODE_STRING_SIMPLE("The number {#} is even."),
|
||||
};
|
||||
|
||||
#define PLURAL_SYNTAX_DATA 8
|
||||
const UnicodeString checkSyntaxtData[PLURAL_SYNTAX_DATA] = {
|
||||
UNICODE_STRING_SIMPLE("odd{foo} odd{bar} other{foobar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo} other{bar} other{foobar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo}"),
|
||||
UNICODE_STRING_SIMPLE("otto{foo} other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("1odd{foo} other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo},other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("od d{foo} other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo}{foobar}other{foo}"),
|
||||
};
|
||||
|
||||
const UnicodeString PLKeywordLookups[6] = {
|
||||
UNICODE_STRING_SIMPLE("zero"),
|
||||
UNICODE_STRING_SIMPLE("one"),
|
||||
UNICODE_STRING_SIMPLE("two"),
|
||||
UNICODE_STRING_SIMPLE("few"),
|
||||
UNICODE_STRING_SIMPLE("many"),
|
||||
UNICODE_STRING_SIMPLE("other"),
|
||||
};
|
||||
|
||||
// The value must be same as PLKeywordLookups[] order.
|
||||
#define PFT_ZERO 0
|
||||
|
@ -78,17 +33,11 @@ void PluralFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
|||
{
|
||||
if (exec) logln("TestSuite PluralFormat");
|
||||
switch (index) {
|
||||
case 0: name = "PluralFormat basic test";
|
||||
if (exec) pluralFormatBasicTest();
|
||||
break;
|
||||
case 1: name = "PluralFormat unit tests";
|
||||
if (exec) pluralFormatUnitTest();
|
||||
break;
|
||||
case 2: name = "PluralFormat locale test";
|
||||
if (exec) pluralFormatLocaleTest();
|
||||
break;
|
||||
TESTCASE(0, pluralFormatBasicTest);
|
||||
TESTCASE(1, pluralFormatUnitTest);
|
||||
TESTCASE(2, pluralFormatLocaleTest);
|
||||
default: name = "";
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,6 +94,35 @@ void PluralFormatTest::pluralFormatBasicTest(/*char *par*/)
|
|||
*/
|
||||
void PluralFormatTest::pluralFormatUnitTest(/*char *par*/)
|
||||
{
|
||||
UnicodeString patternTestData[PLURAL_PATTERN_DATA] = {
|
||||
UNICODE_STRING_SIMPLE("odd {# is odd.} other{# is even.}"),
|
||||
UNICODE_STRING_SIMPLE("other{# is odd or even.}"),
|
||||
UNICODE_STRING_SIMPLE("odd{The number {0, number, #.#0} is odd.}other{The number {0, number, #.#0} is even.}"),
|
||||
UNICODE_STRING_SIMPLE("odd{The number {#} is odd.}other{The number {#} is even.}"),
|
||||
};
|
||||
UnicodeString patternOddTestResult[PLURAL_PATTERN_DATA] = {
|
||||
UNICODE_STRING_SIMPLE(" is odd."),
|
||||
UNICODE_STRING_SIMPLE(" is odd or even."),
|
||||
UNICODE_STRING_SIMPLE("The number {0, number, #.#0} is odd."),
|
||||
UNICODE_STRING_SIMPLE("The number {#} is odd."),
|
||||
};
|
||||
UnicodeString patternEvenTestResult[PLURAL_PATTERN_DATA] = {
|
||||
UNICODE_STRING_SIMPLE(" is even."),
|
||||
UNICODE_STRING_SIMPLE(" is odd or even."),
|
||||
UNICODE_STRING_SIMPLE("The number {0, number, #.#0} is even."),
|
||||
UNICODE_STRING_SIMPLE("The number {#} is even."),
|
||||
};
|
||||
UnicodeString checkSyntaxtData[PLURAL_SYNTAX_DATA] = {
|
||||
UNICODE_STRING_SIMPLE("odd{foo} odd{bar} other{foobar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo} other{bar} other{foobar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo}"),
|
||||
UNICODE_STRING_SIMPLE("otto{foo} other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("1odd{foo} other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo},other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("od d{foo} other{bar}"),
|
||||
UNICODE_STRING_SIMPLE("odd{foo}{foobar}other{foo}"),
|
||||
};
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
PluralRules* plRules = PluralRules::createRules(oddAndEvenRule, status);
|
||||
if (U_FAILURE(status)) {
|
||||
|
@ -200,14 +178,14 @@ void PluralFormatTest::pluralFormatUnitTest(/*char *par*/)
|
|||
|
||||
// ======= Test set locale
|
||||
status = U_ZERO_ERROR;
|
||||
plRules = PluralRules::createRules(UNICODE_STRING_SIMPLE("odd__: n mod 2 is 1"), status);
|
||||
plRules = PluralRules::createRules(UNICODE_STRING_SIMPLE("odd: n mod 2 is 1"), status);
|
||||
PluralFormat pluralFmt = PluralFormat(*plRules, status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("ERROR: Could not create PluralFormat instance in setLocale() test - exitting. ");
|
||||
delete plRules;
|
||||
return;
|
||||
}
|
||||
pluralFmt.applyPattern(UNICODE_STRING_SIMPLE("odd__{odd} other{even}"), status);
|
||||
pluralFmt.applyPattern(UNICODE_STRING_SIMPLE("odd{odd} other{even}"), status);
|
||||
pluralFmt.setLocale(Locale::getEnglish(), status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("ERROR: Could not setLocale() with English locale ");
|
||||
|
@ -268,7 +246,6 @@ void
|
|||
PluralFormatTest::pluralFormatLocaleTest(/*char *par*/)
|
||||
{
|
||||
int8_t pluralResults[PLURAL_TEST_ARRAY_SIZE]; // 0: is for default
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
// ======= Test DefaultRule
|
||||
logln("Testing PluralRules with no rule.");
|
||||
|
@ -475,6 +452,14 @@ PluralFormatTest::helperTestRusults(const char** localeArray,
|
|||
int8_t *expResults) {
|
||||
UErrorCode status;
|
||||
UnicodeString plResult;
|
||||
const UnicodeString PLKeywordLookups[6] = {
|
||||
UNICODE_STRING_SIMPLE("zero"),
|
||||
UNICODE_STRING_SIMPLE("one"),
|
||||
UNICODE_STRING_SIMPLE("two"),
|
||||
UNICODE_STRING_SIMPLE("few"),
|
||||
UNICODE_STRING_SIMPLE("many"),
|
||||
UNICODE_STRING_SIMPLE("other"),
|
||||
};
|
||||
|
||||
for (int32_t i=0; i<capacityOfArray; ++i) {
|
||||
const char *locale = localeArray[i];
|
||||
|
|
|
@ -16,58 +16,8 @@
|
|||
#include "plurults.h"
|
||||
#include "unicode/plurrule.h"
|
||||
|
||||
#if defined( U_DEBUG_CALSVC ) || defined (U_DEBUG_CAL)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define PLURAL_TEST_NUM 13
|
||||
const UnicodeString pluralTestData[PLURAL_TEST_NUM] = {
|
||||
UNICODE_STRING_SIMPLE("a: n is 1"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 is 2"),
|
||||
UNICODE_STRING_SIMPLE("a: n is not 1"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 3 is not 1"),
|
||||
UNICODE_STRING_SIMPLE("a: n in 2..5"),
|
||||
UNICODE_STRING_SIMPLE("a: n not in 2..5"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 in 2..5"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 is 2 and n is not 12"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 in 2..3 or n mod 10 is 5"),
|
||||
UNICODE_STRING_SIMPLE("a: n is 1 or n is 4 or n is 23"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 2 is 1 and n is not 3 and n in 1..11"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 2 is 1 or n mod 5 is 1 and n is not 6"),
|
||||
"",
|
||||
};
|
||||
|
||||
|
||||
const int32_t pluralTestResult[PLURAL_TEST_NUM][30] = {
|
||||
{1, 0},
|
||||
{2,12,22, 0},
|
||||
{0,2,3,4,5,0},
|
||||
{0,2,3,5,6,8,9,0},
|
||||
{2,3,4,5,0},
|
||||
{0,1,6,7,8, 0},
|
||||
{2,3,4,5,12,13,14,15,22,23,24,25,0},
|
||||
{2,22,32,42,0},
|
||||
{2,3,5,12,13,15,22,23,25,0},
|
||||
{1,4,23,0},
|
||||
{1,5,7,9,11,0},
|
||||
{1,3,5,7,9,11,13,15,16,0},
|
||||
};
|
||||
|
||||
|
||||
#define MAX_EQ_ROW 2
|
||||
#define MAX_EQ_COL 5
|
||||
UnicodeString testEquRules[MAX_EQ_ROW][MAX_EQ_COL] = {
|
||||
{ UNICODE_STRING_SIMPLE("a: n in 2..3"),
|
||||
UNICODE_STRING_SIMPLE("a: n is 2 or n is 3"),
|
||||
UNICODE_STRING_SIMPLE( "a:n is 3 and n in 2..5 or n is 2"),
|
||||
"",
|
||||
},
|
||||
{ UNICODE_STRING_SIMPLE("a: n is 12; b:n mod 10 in 2..3"),
|
||||
UNICODE_STRING_SIMPLE("b: n mod 10 in 2..3 and n is not 12; a: n in 12..12"),
|
||||
UNICODE_STRING_SIMPLE("b: n is 13; a: n in 12..13; b: n mod 10 is 2 or n mod 10 is 3"),
|
||||
"",
|
||||
}
|
||||
};
|
||||
void setupResult(const int32_t testSource[], char result[], int32_t* max);
|
||||
UBool checkEqual(PluralRules *test, char *result, int32_t max);
|
||||
UBool testEquality(PluralRules *test);
|
||||
|
@ -80,29 +30,46 @@ void PluralRulesTest::runIndexedTest( int32_t index, UBool exec, const char* &na
|
|||
{
|
||||
if (exec) logln("TestSuite PluralRulesAPI");
|
||||
switch (index) {
|
||||
case 0: name = "PluralRules API test";
|
||||
if (exec) {
|
||||
logln("PluralRules API test---"); logln("");
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale saveLocale;
|
||||
Locale::setDefault(Locale::getEnglish(), status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("ERROR: Could not set default locale, test may not give correct results");
|
||||
}
|
||||
testAPI(/*par*/);
|
||||
Locale::setDefault(saveLocale, status);
|
||||
}
|
||||
break;
|
||||
|
||||
TESTCASE(0, testAPI);
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
|
||||
#define PLURAL_TEST_NUM 13
|
||||
/**
|
||||
* Test various generic API methods of PluralRules for API coverage.
|
||||
*/
|
||||
void PluralRulesTest::testAPI(/*char *par*/)
|
||||
{
|
||||
UnicodeString pluralTestData[PLURAL_TEST_NUM] = {
|
||||
UNICODE_STRING_SIMPLE("a: n is 1"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 is 2"),
|
||||
UNICODE_STRING_SIMPLE("a: n is not 1"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 3 is not 1"),
|
||||
UNICODE_STRING_SIMPLE("a: n in 2..5"),
|
||||
UNICODE_STRING_SIMPLE("a: n not in 2..5"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 in 2..5"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 is 2 and n is not 12"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 10 in 2..3 or n mod 10 is 5"),
|
||||
UNICODE_STRING_SIMPLE("a: n is 1 or n is 4 or n is 23"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 2 is 1 and n is not 3 and n in 1..11"),
|
||||
UNICODE_STRING_SIMPLE("a: n mod 2 is 1 or n mod 5 is 1 and n is not 6"),
|
||||
"",
|
||||
};
|
||||
static const int32_t pluralTestResult[PLURAL_TEST_NUM][30] = {
|
||||
{1, 0},
|
||||
{2,12,22, 0},
|
||||
{0,2,3,4,5,0},
|
||||
{0,2,3,5,6,8,9,0},
|
||||
{2,3,4,5,0},
|
||||
{0,1,6,7,8, 0},
|
||||
{2,3,4,5,12,13,14,15,22,23,24,25,0},
|
||||
{2,22,32,42,0},
|
||||
{2,3,5,12,13,15,22,23,25,0},
|
||||
{1,4,23,0},
|
||||
{1,5,7,9,11,0},
|
||||
{1,3,5,7,9,11,13,15,16,0},
|
||||
};
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
// ======= Test constructors
|
||||
|
@ -221,7 +188,21 @@ UBool checkEqual(PluralRules *test, char *result, int32_t max) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#define MAX_EQ_ROW 2
|
||||
#define MAX_EQ_COL 5
|
||||
UBool testEquality(PluralRules *test) {
|
||||
UnicodeString testEquRules[MAX_EQ_ROW][MAX_EQ_COL] = {
|
||||
{ UNICODE_STRING_SIMPLE("a: n in 2..3"),
|
||||
UNICODE_STRING_SIMPLE("a: n is 2 or n is 3"),
|
||||
UNICODE_STRING_SIMPLE( "a:n is 3 and n in 2..5 or n is 2"),
|
||||
"",
|
||||
},
|
||||
{ UNICODE_STRING_SIMPLE("a: n is 12; b:n mod 10 in 2..3"),
|
||||
UNICODE_STRING_SIMPLE("b: n mod 10 in 2..3 and n is not 12; a: n in 12..12"),
|
||||
UNICODE_STRING_SIMPLE("b: n is 13; a: n in 12..13; b: n mod 10 is 2 or n mod 10 is 3"),
|
||||
"",
|
||||
}
|
||||
};
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UnicodeString key[MAX_EQ_COL];
|
||||
UBool ret=TRUE;
|
||||
|
@ -259,3 +240,4 @@ UBool testEquality(PluralRules *test) {
|
|||
return ret;
|
||||
}
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue