Commit acae4d71 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Correctly identify delimiters

It is not correct to assume that the delimiters will be in the same
position in the formatted number string in every locale. Specifically,
for Hindi, the formatted string is "1,23,456.78", which caused 3 and 6
to be sent as delimiters. Look for the delimiters after 3 and 6 instead.

Bug: 998039
Change-Id: If3e7e1c245f458224c0916a2eb6b78acd5c61581
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774219Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691493}
parent 647d6642
...@@ -933,8 +933,15 @@ void PrintPreviewHandler::GetLocaleInformation(base::Value* settings) { ...@@ -933,8 +933,15 @@ void PrintPreviewHandler::GetLocaleInformation(base::Value* settings) {
// Getting the number formatting based on the locale and writing to // Getting the number formatting based on the locale and writing to
// dictionary. // dictionary.
base::string16 number_format = base::FormatDouble(123456.78, 2); base::string16 number_format = base::FormatDouble(123456.78, 2);
settings->SetStringKey(kDecimalDelimiter, number_format.substr(7, 1)); size_t thousands_pos = number_format.find('3') + 1;
settings->SetStringKey(kThousandsDelimiter, number_format.substr(3, 1)); base::string16 thousands_delimiter = number_format.substr(thousands_pos, 1);
if (number_format[thousands_pos] == '4')
thousands_delimiter.clear();
size_t decimal_pos = number_format.find('6') + 1;
DCHECK_NE(number_format[decimal_pos], '7');
base::string16 decimal_delimiter = number_format.substr(decimal_pos, 1);
settings->SetStringKey(kDecimalDelimiter, decimal_delimiter);
settings->SetStringKey(kThousandsDelimiter, thousands_delimiter);
settings->SetIntKey(kUnitType, system); settings->SetIntKey(kUnitType, system);
} }
......
...@@ -469,10 +469,9 @@ TEST_F(PrintPreviewHandlerTest, InitialSettingsHiLocale) { ...@@ -469,10 +469,9 @@ TEST_F(PrintPreviewHandlerTest, InitialSettingsHiLocale) {
InitializeWithLocale("hi"); InitializeWithLocale("hi");
// Verify initial settings were sent for Hindi. // Verify initial settings were sent for Hindi.
// TODO(crbug.com/998039): Fix the incorrect delimiters.
ValidateInitialSettingsForLocale(*web_ui()->call_data().back(), ValidateInitialSettingsForLocale(*web_ui()->call_data().back(),
kDummyPrinterName, kDummyInitiatorName, "hi", kDummyPrinterName, kDummyInitiatorName, "hi",
"3", "6", {}); ",", ".", {});
} }
TEST_F(PrintPreviewHandlerTest, InitialSettingsRuLocale) { TEST_F(PrintPreviewHandlerTest, InitialSettingsRuLocale) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment