← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba

 

Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
Fixed handling of what is most likely a mistake on the part of the user in a picture string, e.g., "1,000,00" where there are multiple grouping intervals, but they're not equally spaced.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/157553

Fixed handling of what is most likely a mistake on the part of the user in a picture string, e.g., "1,000,00" where there are multiple grouping intervals, but they're not equally spaced.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/157553
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/numerics/format_integer.cpp'
--- src/runtime/numerics/format_integer.cpp	2013-04-04 16:15:30 +0000
+++ src/runtime/numerics/format_integer.cpp	2013-04-07 18:00:32 +0000
@@ -468,11 +468,11 @@
     bool grouping_interval_possible = true;
     unicode::code_point grouping_separator_cp = 0;
     int grouping_separators = 0;
-    zstring::size_type pos = 0, prev_grouping_pos = zstring::npos;
+    utf8::size_type pos = 1, prev_grouping_pos = utf8::npos;
 
     semicolon_counter = semicolons;
     while ( ++u != u_picture_str.end() ) {
-      cp = *u, ++pos;
+      cp = *u;
       if ( cp == '#' ) {
         if ( got_mandatory_digit ) {
           //
@@ -540,7 +540,7 @@
             grouping_interval = pos - prev_grouping_pos;
           else if ( pos - prev_grouping_pos != grouping_interval )
             grouping_interval_possible = false;
-          prev_grouping_pos = pos;
+          prev_grouping_pos = pos + 1;
         }
       } else {
         throw XQUERY_EXCEPTION(
@@ -554,6 +554,7 @@
         );
       }
       u_pic_format += cp;
+      ++pos;
     } // while
 
     if ( got_grouping_separator ) {
@@ -571,9 +572,23 @@
         ERROR_LOC( loc )
       );
     }
+
     if ( grouping_interval_possible ) {
-      if ( !grouping_interval && grouping_separator_cp )
-        grouping_interval = pos - prev_grouping_pos;
+      if ( !grouping_interval ) {
+        if ( grouping_separator_cp ) {
+          //
+          // There's only a single grouping separator, e.g., "1,000".
+          //
+          grouping_interval = pos - prev_grouping_pos;
+        }
+      } else if ( pos - prev_grouping_pos != grouping_interval ) {
+        //
+        // There are multiple grouping separators, but they're not equally
+        // spaced from the last digit, e.g., "1,000,00".  (This is most likely
+        // a mistake on the part of the user.)
+        //
+        grouping_interval = 0;
+      }
       pic->primary.grouping_interval = grouping_interval;
     } else
       pic->primary.mandatory_grouping_seps = grouping_separators;

=== added file 'test/rbkt/ExpQueryResults/zorba/math/format_integer/format-integer-1-10.xml.res'
--- test/rbkt/ExpQueryResults/zorba/math/format_integer/format-integer-1-10.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/math/format_integer/format-integer-1-10.xml.res	2013-04-07 18:00:32 +0000
@@ -0,0 +1,1 @@
+true

=== added file 'test/rbkt/Queries/zorba/math/format_integer/format-integer-1-10.xq'
--- test/rbkt/Queries/zorba/math/format_integer/format-integer-1-10.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/math/format_integer/format-integer-1-10.xq	2013-04-07 18:00:32 +0000
@@ -0,0 +1,1 @@
+fn:format-integer( 123456789, "0,000,00" ) eq "1234,567,89"


Follow ups