Fix AFPercent_Format() for separator style 4. This style uses apostrophes as the separator. Change-Id: I1416d2129bfb427ad6b3971af1e6df8905e2465c Reviewed-on: https://pdfium-review.googlesource.com/c/51072 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Wei Li <weili@chromium.org>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index 5f0fdfd..171552f 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp
@@ -179,10 +179,14 @@ ASSERT(IsStyleWithDigitSeparator(style)); return style == 0 ? ',' : '.'; } + +bool IsStyleWithApostropheSeparator(int style) { + return style >= 4; +} #endif bool IsStyleWithCommaDecimalMark(int style) { - return style >= 2; + return style == 2 || style == 3; } char DecimalMarkForStyle(int style) { @@ -791,8 +795,6 @@ if (iDec < 0 || iSepStyle < 0 || iSepStyle > kMaxSepStyle) return CJS_Result::Failure(JSMessage::kValueError); - iSepStyle = ValidStyleOrZero(iSepStyle); - WideString& Value = pEvent->Value(); ByteString strValue = StrTrim(Value.ToDefANSI()); if (strValue.IsEmpty()) @@ -839,8 +841,10 @@ if (iDec2 == 0) strValue.Insert(iDec2, '0'); } - if (IsStyleWithDigitSeparator(iSepStyle)) { - char cSeparator = DigitSeparatorForStyle(iSepStyle); + bool bUseDigitSeparator = IsStyleWithDigitSeparator(iSepStyle); + if (bUseDigitSeparator || IsStyleWithApostropheSeparator(iSepStyle)) { + char cSeparator = + bUseDigitSeparator ? DigitSeparatorForStyle(iSepStyle) : '\''; for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) { strValue.Insert(iDecPositive, cSeparator); iMax++;
diff --git a/testing/resources/javascript/public_methods_expected.txt b/testing/resources/javascript/public_methods_expected.txt index 6131da8..2169d0c 100644 --- a/testing/resources/javascript/public_methods_expected.txt +++ b/testing/resources/javascript/public_methods_expected.txt
@@ -182,42 +182,42 @@ Alert: PASS: AFPercent_Format(1, 1) = 98765432100.1% Alert: PASS: AFPercent_Format(1, 2) = 98.765.432.100,1% Alert: PASS: AFPercent_Format(1, 3) = 98765432100,1% -Alert: FAIL: AFPercent_Format(1, 4) = 98,765,432,100.1%, expected 98'765'432'100.1% +Alert: PASS: AFPercent_Format(1, 4) = 98'765'432'100.1% Alert: PASS: AFPercent_Format(2, 0) = 98,765,432,100.12% Alert: PASS: AFPercent_Format(2, 1) = 98765432100.12% Alert: PASS: AFPercent_Format(2, 2) = 98.765.432.100,12% Alert: PASS: AFPercent_Format(2, 3) = 98765432100,12% -Alert: FAIL: AFPercent_Format(2, 4) = 98,765,432,100.12%, expected 98'765'432'100.12% +Alert: PASS: AFPercent_Format(2, 4) = 98'765'432'100.12% Alert: PASS: AFPercent_Format(3, 0) = 98,765,432,100.123% Alert: PASS: AFPercent_Format(3, 1) = 98765432100.123% Alert: PASS: AFPercent_Format(3, 2) = 98.765.432.100,123% Alert: PASS: AFPercent_Format(3, 3) = 98765432100,123% -Alert: FAIL: AFPercent_Format(3, 4) = 98,765,432,100.123%, expected 98'765'432'100.123% +Alert: PASS: AFPercent_Format(3, 4) = 98'765'432'100.123% Alert: PASS: AFPercent_Format(10, 0) = 98,765,432,100.1234130859% Alert: PASS: AFPercent_Format(10, 1) = 98765432100.1234130859% Alert: PASS: AFPercent_Format(10, 2) = 98.765.432.100,1234130859% Alert: PASS: AFPercent_Format(10, 3) = 98765432100,1234130859% -Alert: FAIL: AFPercent_Format(10, 4) = 98,765,432,100.1234130859%, expected 98'765'432'100.1234130859% +Alert: PASS: AFPercent_Format(10, 4) = 98'765'432'100.1234130859% Alert: PASS: AFPercent_Format(1, 0) = 98,765,432,100.0% Alert: PASS: AFPercent_Format(1, 1) = 98765432100.0% Alert: PASS: AFPercent_Format(1, 2) = 98.765.432.100,0% Alert: PASS: AFPercent_Format(1, 3) = 98765432100,0% -Alert: FAIL: AFPercent_Format(1, 4) = 98,765,432,100.0%, expected 98'765'432'100.0% +Alert: PASS: AFPercent_Format(1, 4) = 98'765'432'100.0% Alert: PASS: AFPercent_Format(2, 0) = 98,765,432,100.00% Alert: PASS: AFPercent_Format(2, 1) = 98765432100.00% Alert: PASS: AFPercent_Format(2, 2) = 98.765.432.100,00% Alert: PASS: AFPercent_Format(2, 3) = 98765432100,00% -Alert: FAIL: AFPercent_Format(2, 4) = 98,765,432,100.00%, expected 98'765'432'100.00% +Alert: PASS: AFPercent_Format(2, 4) = 98'765'432'100.00% Alert: PASS: AFPercent_Format(3, 0) = 98,765,432,100.000% Alert: PASS: AFPercent_Format(3, 1) = 98765432100.000% Alert: PASS: AFPercent_Format(3, 2) = 98.765.432.100,000% Alert: PASS: AFPercent_Format(3, 3) = 98765432100,000% -Alert: FAIL: AFPercent_Format(3, 4) = 98,765,432,100.000%, expected 98'765'432'100.000% +Alert: PASS: AFPercent_Format(3, 4) = 98'765'432'100.000% Alert: PASS: AFPercent_Format(10, 0) = 98,765,432,100.0000000000% Alert: PASS: AFPercent_Format(10, 1) = 98765432100.0000000000% Alert: PASS: AFPercent_Format(10, 2) = 98.765.432.100,0000000000% Alert: PASS: AFPercent_Format(10, 3) = 98765432100,0000000000% -Alert: FAIL: AFPercent_Format(10, 4) = 98,765,432,100.0000000000%, expected 98'765'432'100.0000000000% +Alert: PASS: AFPercent_Format(10, 4) = 98'765'432'100.0000000000% Alert: ********************** Alert: PASS: AFPercent_Keystroke() threw AFPercent_Keystroke: Incorrect number of parameters passed to function. Alert: PASS: AFPercent_Keystroke(1) threw AFPercent_Keystroke: Incorrect number of parameters passed to function.