Changeset 7398

Show
Ignore:
Timestamp:
02/21/07 21:47:04 (23 months ago)
Author:
peller
Message:

Fix handling of places flag on regexp creation. References #2475

Location:
trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/number.js

    r7361 r7398  
    204204                                exponent: false}; 
    205205                        var parts = format.split('.'); 
    206                         if(parts.length == 1){parts.fractional = false;} 
     206                        var places = options.places; 
     207                        if(parts.length == 1 || places === 0){flags.fractional = false;} 
    207208                        else{ 
    208                                 var places = options.places; 
    209209                                if(typeof places == "undefined"){ places = parts[1].lastIndexOf('0')+1; } 
    210                                 if(places){parts.fractional = true;} // required fraction 
     210                                if(places){flags.fractional = true;} // required fraction 
     211                                if(!options.places && (places < parts[1].length)){ places += "," + parts[1].length; } 
    211212                                flags.places = places; 
    212                                 if(places < parts[1].length){ flags.places += "," + parts[1].length; } 
    213213                        } 
    214214                        var groups = parts[0].split(','); 
     
    224224 
    225225        if(!options.strict){ 
    226                 // TODO: handle .### with no leading integer? 
     226                //TODO: handle .### with no leading integer as a strict option only? 
    227227                //TODO: !strict: make currency symbol too 
    228228        } 
     
    260260                return NaN; //NaN 
    261261        } 
    262         var numberExpression = results[1]; 
    263         if(typeof numberExpression == 'undefined'){ 
     262        var absoluteMatch = results[1]; 
     263        if(typeof absoluteMatch == 'undefined'){ 
    264264                // matched the negative pattern 
    265265                var negative = true; 
    266                 numberExpression = results[2]; 
    267         } 
    268         numberExpression = numberExpression.replace(group, "", "g").replace(decimal, "."); 
    269         value = Number(numberExpression); 
     266                absoluteMatch = results[2]; 
     267        } 
     268        absoluteMatch = absoluteMatch.replace(group, "", "g").replace(decimal, "."); 
     269        value = Number(absoluteMatch); 
    270270 
    271271        if(!isNaN(value)){ 
  • trunk/src/regexp.js

    r7365 r7398  
    332332 
    333333        // real number RE 
    334         return "(?:(?:"+ integerRE + decimalRE + ")|(?:" + decimalRE + "))" + exponentRE; // String 
     334        var realRE = integerRE + decimalRE; 
     335        // allow for decimals without integers, e.g. .25 
     336        if(decimalRE){realRE = "(?:(?:"+ realRE + ")|(?:" + decimalRE + "))";} 
     337        return realRE + exponentRE; // String 
    335338} 
    336339