• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Index: source/i18n/digitlst.cpp
2===================================================================
3--- source/i18n/digitlst.cpp	(revision 88316)
4+++ source/i18n/digitlst.cpp	(working copy)
5@@ -60,6 +60,18 @@
6
7 U_NAMESPACE_BEGIN
8
9+static void
10+loadDecimalChar() {
11+    if (gDecimal == 0) {
12+        char rep[MAX_DIGITS];
13+        // For machines that decide to change the decimal on you,
14+        // and try to be too smart with localization.
15+        // This normally should be just a '.'.
16+        sprintf(rep, "%+1.1f", 1.0);
17+        gDecimal = rep[2];
18+    }
19+}
20+
21 // -------------------------------------
22 // default constructor
23
24@@ -398,15 +410,6 @@
25     }
26     DigitList *nonConstThis = const_cast<DigitList *>(this);
27
28-    if (gDecimal == 0) {
29-        char rep[MAX_DIGITS];
30-        // For machines that decide to change the decimal on you,
31-        // and try to be too smart with localization.
32-        // This normally should be just a '.'.
33-        sprintf(rep, "%+1.1f", 1.0);
34-        gDecimal = rep[2];
35-    }
36-
37     if (isZero()) {
38         nonConstThis->fDouble = 0.0;
39         if (decNumberIsNegative(fDecNumber)) {
40@@ -441,6 +444,7 @@
41         }
42         U_ASSERT(uprv_strlen(&s[0]) < MAX_DBL_DIGITS+18);
43
44+        loadDecimalChar();
45         if (gDecimal != '.') {
46             char *decimalPt = strchr(s, '.');
47             if (decimalPt != NULL) {
48@@ -727,6 +731,17 @@
49     sprintf(rep, "%+1.*e", MAX_DBL_DIGITS - 1, source);
50     U_ASSERT(uprv_strlen(rep) < sizeof(rep));
51
52+    // uprv_decNumberFromString() will parse the string expecting '.' as a
53+    // decimal separator, however sprintf() can use ',' in certain locales.
54+    // Overwrite a different decimal separator with '.' here before proceeding.
55+    loadDecimalChar();
56+    if (gDecimal != '.') {
57+        char *decimalPt = strchr(rep, gDecimal);
58+        if (decimalPt != NULL) {
59+            *decimalPt = '.';
60+        }
61+    }
62+
63     // Create a decNumber from the string.
64     uprv_decNumberFromString(fDecNumber, rep, &fContext);
65     uprv_decNumberTrim(fDecNumber);
66