ICU-4630 test port of missing ICU4J changes for Hebrew to ICU4C

X-SVN-Rev: 18180
This commit is contained in:
Doug Felt 2005-07-09 02:13:00 +00:00
parent cecf675b8a
commit 9619133865
3 changed files with 52 additions and 18 deletions

View file

@ -681,7 +681,8 @@ ModulusSubstitution::doParse(const UnicodeString& text,
ruleToUse->doParse(text, parsePosition, FALSE, upperBound, result);
if (parsePosition.getIndex() != 0) {
double tempResult = result.getDouble();
UErrorCode status = U_ZERO_ERROR;
double tempResult = result.getDouble(status);
tempResult = composeRuleValue(tempResult, baseValue);
result.setDouble(tempResult);
}
@ -881,7 +882,7 @@ FractionalPartSubstitution::doParse(const UnicodeString& text,
}
if (fmt) {
fmt->parse(workText, temp, workPos);
digit = temp.getLong();
digit = temp.getLong(status);
}
}
@ -950,7 +951,7 @@ NumeratorSubstitution::doSubstitution(double number, UnicodeString& toInsertInto
int64_t nf =longNF;
int32_t len = toInsertInto.length();
while ((nf *= 10) < denominator) {
toInsertInto.insert(pos + getPos(), (UChar)0x0020);
toInsertInto.insert(pos + getPos(), gSpace);
ruleSet->format((int64_t)0, toInsertInto, pos + getPos());
}
pos += toInsertInto.length() - len;
@ -997,12 +998,10 @@ NumeratorSubstitution::doParse(const UnicodeString& text,
if (withZeros) {
ParsePosition workPos(1);
Formattable temp;
int32_t digit;
while (workText.length() > 0 && workPos.getIndex() != 0) {
workPos.setIndex(0);
getRuleSet()->parse(workText, workPos, 1, temp); // parse zero or nothing at all
digit = temp.getLong(status);
if (workPos.getIndex() == 0) {
// we failed, either there were no more zeros, or the number was formatted with digits
// either way, we're done
@ -1012,14 +1011,14 @@ NumeratorSubstitution::doParse(const UnicodeString& text,
++zeroCount;
parsePosition.setIndex(parsePosition.getIndex() + workPos.getIndex());
workText.remove(0, workPos.getIndex());
while (workText.length() > 0 && workText.charAt(0) == 0x0020) {
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()); // arrgh!
workText.remove(0, (int32_t)parsePosition.getIndex());
parsePosition.setIndex(0);
}
@ -1031,7 +1030,7 @@ NumeratorSubstitution::doParse(const UnicodeString& text,
// force this to not bother trying all the base values?
// compute the 'effective' base and prescale the value down
int64_t n = result.getLong();
int64_t n = result.getLong(status); // force conversion!
int64_t d = 1;
int32_t pow = 0;
while (d <= n) {
@ -1064,6 +1063,8 @@ NumeratorSubstitution::getDynamicClassID() const {
return getStaticClassID();
}
const UChar NumeratorSubstitution::LTLT[] = { 0x003c, 0x003c };
//===================================================================
// NullSubstitution
//===================================================================

View file

@ -481,8 +481,7 @@ public:
: NFSubstitution(_pos, _ruleSet, formatter, fixdesc(description), status), denominator(_denominator)
{
ldenominator = util64_fromDouble(denominator);
UChar LTLT[] = { 0x003c, 0x003c, 0 };
withZeros = description.endsWith(LTLT);
withZeros = description.endsWith(LTLT, 2);
}
virtual UBool operator==(const NFSubstitution& rhs) const;
@ -503,8 +502,9 @@ public:
virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
private:
static const char fgClassID;
static const UChar LTLT[2];
static UnicodeString fixdesc(const UnicodeString& desc) {
if (desc.endsWith("<<")) {
if (desc.endsWith(LTLT, 2)) {
UnicodeString result(desc, 0, desc.length()-1);
return result;
}

View file

@ -77,21 +77,54 @@ void IntlTestRBNF::runIndexedTest(int32_t index, UBool exec, const char* &name,
void IntlTestRBNF::TestHebrewFraction() {
// this is the expected output for 123.45, with no '<' in it.
UChar text[] = {
0x05de, 0x05d0, 0x05d4,0x0020,
UChar text1[] = {
0x05de, 0x05d0, 0x05d4, 0x0020,
0x05e2, 0x05e9, 0x05e8, 0x05d9, 0x05dd, 0x0020,
0x05d5, 0x05e9, 0x05dc, 0x05d5, 0x05e9, 0x0020,
0x05e0, 0x05e7, 0x05d5, 0x05d3, 0x05d4, 0x0020,
0x05d0, 0x05e8, 0x05d1, 0x05e2, 0x05d9, 0x05dd, 0x0020,
0x05d5, 0x05d7, 0x05de, 0x05e9, 0x0000,
};
UChar text2[] = {
0x05DE, 0x05D0, 0x05D4, 0x0020,
0x05E2, 0x05E9, 0x05E8, 0x05D9, 0x05DD, 0x0020,
0x05D5, 0x05E9, 0x05DC, 0x05D5, 0x05E9, 0x0020,
0x05E0, 0x05E7, 0x05D5, 0x05D3, 0x05D4, 0x0020,
0x05D0, 0x05E4, 0x05E1, 0x0020,
0x05D0, 0x05E4, 0x05E1, 0x0020,
0x05D0, 0x05E8, 0x05D1, 0x05E2, 0x05D9, 0x05DD, 0x0020,
0x05D5, 0x05D7, 0x05DE, 0x05E9, 0x0000,
};
UErrorCode status = U_ZERO_ERROR;
RuleBasedNumberFormat* formatter = new RuleBasedNumberFormat(URBNF_SPELLOUT, "he_IW", status);
UnicodeString expected(text);
RuleBasedNumberFormat* formatter = new RuleBasedNumberFormat(URBNF_SPELLOUT, "he_IL", status);
UnicodeString result;
formatter->format(123.450000, result);
if (result != expected) {
errln((UnicodeString)"expected '" + TestUtility::hex(expected) + "'\nbut got: '" + TestUtility::hex(result) + "'");
Formattable parseResult;
ParsePosition pp(0);
{
UnicodeString expected(text1);
formatter->format(123.45, result);
if (result != expected) {
errln((UnicodeString)"expected '" + TestUtility::hex(expected) + "'\nbut got: '" + TestUtility::hex(result) + "'");
} else {
formatter->parse(result, parseResult, pp);
if (parseResult.getDouble() != 123.45) {
errln("expected 123.45 but got: %g", parseResult.getDouble());
}
}
}
{
UnicodeString expected(text2);
result.remove();
formatter->format(123.0045, result);
if (result != expected) {
errln((UnicodeString)"expected '" + TestUtility::hex(expected) + "'\nbut got: '" + TestUtility::hex(result) + "'");
} else {
pp.setIndex(0);
formatter->parse(result, parseResult, pp);
if (parseResult.getDouble() != 123.0045) {
errln("expected 123.0045 but got: %g", parseResult.getDouble());
}
}
}
delete formatter;
}