Changeset 2156 for trunk


Ignore:
Timestamp:
Mar 27, 2011, 12:32:55 PM (13 years ago)
Author:
mmc
Message:

Fixed a problem with the number parsing routine. Wasn't getting the
full units for something like "10.2meV", thinking it was just "10.2V".
Working better now for all combinations of spaces, slashes, and multiple
units.

Location:
trunk/lang/tcl/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lang/tcl/scripts/objects/number/number.rp

    r2154 r2156  
    103103
    104104    import string {val {defunits ""}} {
    105 puts "IMPORTING: $val (number with units $defunits)"
    106105        if {[regexp {^([-+]?(?:[0-9]+\.|\.)?[0-9]+(?:[eE][-+]?[0-9]+)?)( *(?:[a-zA-Z]+[0-9]*)+(?:\/(?:[a-zA-Z]+[0-9]*)+)*)*$} $val match num units]} {
    107106            set sys [Rappture::Units::System::for $units]
  • trunk/lang/tcl/scripts/validations/number.tcl

    r2080 r2156  
    1515    upvar $numvar num
    1616    upvar $unitsvar units
    17     return [regexp {^([-+]?(?:[0-9]+\.|\.)?[0-9]+(?:[eE][-+]?[0-9]+)?)( *(?:[a-zA-Z]+[0-9]*)+(?:\/(?:[a-zA-Z]+[0-9]*)+)*)*$} $str match num units]
     17    if {![regexp {^([-+]?(?:[0-9]+\.|\.)?[0-9]+(?:[eE][-+]?[0-9]+)?)( *[a-zA-Z/]?[a-zA-Z0-9/ \t]*)$} $str match num rest]} {
     18        return 0
     19    }
     20    regsub -all {[ \t]+} $rest "" rest  ;# strip out spaces from units
     21    if {$rest eq ""} {
     22        set units ""
     23    } elseif {![regexp {^(/?[a-zA-Z]+[0-9]*)*$} $rest units]} {
     24        return 0  ;# units failed to match
     25    }
     26    return 1;
    1827}
    1928
Note: See TracChangeset for help on using the changeset viewer.