Permalink
Browse files

Respect escaped format separators ";"

  • Loading branch information...
1 parent e9a4000 commit 792d495a918c2d0a59debe9becf0f3ca32687d24 @therazor committed Jun 7, 2012
Showing with 25 additions and 2 deletions.
  1. +24 −2 lib/globalize.js
  2. +1 −0 test/customFormat.js
View
@@ -787,7 +787,29 @@ formatDate = function( value, format, culture ) {
return value.toString();
function notEscapedSplit( stringToSplit, delimiter, limit ) {
- return stringToSplit.split(delimiter, limit);
+ var ret = [],
+ max = stringToSplit.length,
+ i = 0,
+ lastTokenEndsAt = 0;
+
+ while ( i < max && ret.length < limit ) {
+ if ( stringToSplit.charAt( i ) === delimiter ) {
+ var token = stringToSplit.substring( lastTokenEndsAt, i );
+
+ if ( token.match(/\\*$/).shift().length % 2 === 0 ) {
+ ret.push( token );
+ lastTokenEndsAt = i + 1;
+ }
+ }
+ i++;
+ }
+
+ if ( !ret.length )
+ ret.push( stringToSplit );
+ else if ( ret.length < limit )
+ ret.push( stringToSplit.substring( lastTokenEndsAt ) );
+
+ return ret;
}
function numberOfSeparators( startPosition, endPosition, formatInfo ) {
@@ -820,7 +842,7 @@ formatDate = function( value, format, culture ) {
patterns[i] = patterns[0];
i--;
}
-
+
if ( patterns.length === 3 )
zeroPattern = patterns[2];
else
View
@@ -75,6 +75,7 @@ test("Number Formatting - custom w/ pattern for +/-", function() {
// zero or positive for a negative number.
equal( Globalize.format(-0.00001, "positive;negative;zero;ignored"), "negative" );
equal( Globalize.format(-0.00001, "Positive: 0;;zero;ignored"), "zero" );
+ equal( Globalize.format(0, "Positive;Negative;zero"), "zero" );
});
test("Number Formatting - custom w/ non-formatting text", function() {

0 comments on commit 792d495

Please sign in to comment.