Changeset 3511


Ignore:
Timestamp:
Mar 16, 2013 9:31:43 AM (7 years ago)
Author:
gah
Message:

fixes for lack of string trim for numbers and unit conversion

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/numberentry.tcl

    r3330 r3511  
    4848    set _owner $owner
    4949    set _path $path
    50 
     50   
    5151    #
    5252    # Figure out what sort of control to create
     
    5454    set presets ""
    5555    foreach pre [$_owner xml children -type preset $path] {
    56         lappend presets \
    57             [$_owner xml get $path.$pre.value] \
    58             [$_owner xml get $path.$pre.label]
    59     }
    60 
     56        set value [string trim [$_owner xml get $path.$pre.value]]
     57        set label [$_owner xml get $path.$pre.label]
     58        lappend presets $value $label
     59    }
     60   
    6161    set class Rappture::Gauge
    62     set units [$_owner xml get $path.units]
     62    set units [string trim [$_owner xml get $path.units]]
    6363    if {$units != ""} {
    6464        set desc [Rappture::Units::description $units]
     
    6767        }
    6868    }
    69 
     69   
    7070    #
    7171    # Create the widget and configure it properly based on other
     
    7777    pack $itk_component(gauge) -expand yes -fill both
    7878    bind $itk_component(gauge) <<Value>> [itcl::code $this _newValue]
    79 
    80     set min [$_owner xml get $path.min]
    81     if {$min ne ""} { $itk_component(gauge) configure -minvalue $min }
    82 
    83     set max [$_owner xml get $path.max]
    84     if {$max ne ""} { $itk_component(gauge) configure -maxvalue $max }
     79   
     80    set min [string trim [$_owner xml get $path.min]]
     81    if {$min ne ""} {
     82        $itk_component(gauge) configure -minvalue $min
     83    }
     84   
     85    set max [string trim [$_owner xml get $path.max]]
     86    if {$max ne ""} {
     87        $itk_component(gauge) configure -maxvalue $max
     88    }
    8589
    8690    if {$class == "Rappture::Gauge" && $min ne "" && $max ne ""} {
    87         set color [$_owner xml get $path.about.color]
     91        set color [string trim [$_owner xml get $path.about.color]]
    8892        if {$color == ""} {
    8993            # deprecated.  Color should be in "about"
    90             set color [$_owner xml get $path.color]
     94            set color [string trim [$_owner xml get $path.color]]
    9195        }
    9296        if {$color != ""}  {
     
    100104            }
    101105            $itk_component(gauge) configure \
    102                 -spectrum [Rappture::Spectrum ::#auto $color -units $units]
     106                -spectrum [Rappture::Spectrum ::\#auto $color -units $units]
    103107        }
    104108    }
    105109
    106110    # if the control has an icon, plug it in
    107     set str [$_owner xml get $path.about.icon]
     111    set str [string trim [$_owner xml get $path.about.icon]]
    108112    if {$str ne ""} {
    109113        $itk_component(gauge) configure -image [image create photo -data $str]
    110114    }
    111 
    112115    eval itk_initialize $args
    113116
     
    115118    # Assign the default value to this widget, if there is one.
    116119    #
    117     set str [$_owner xml get $path.default]
    118     if {$str ne ""} { $itk_component(gauge) value $str }
     120    set str [string trim [$_owner xml get $path.default]]
     121    if {$str ne ""} {
     122        $itk_component(gauge) value $str
     123    }
    119124}
    120125
     
    180185    set str [$_owner xml get $_path.about.description]
    181186
    182     set units [$_owner xml get $_path.units]
    183     set min [$_owner xml get $_path.min]
    184     set max [$_owner xml get $_path.max]
     187    set units [string trim [$_owner xml get $_path.units]]
     188    set min [string trim [$_owner xml get $_path.min]]
     189    set max [string trim [$_owner xml get $_path.max]]
    185190
    186191    if {$units != "" || $min != "" || $max != ""} {
  • trunk/lang/tcl/src/RpUnitsTclInterface.cc

    r3177 r3511  
    3838 */
    3939
     40#include <algorithm>
     41#include <functional>
     42#include <cctype>
     43
     44// Trim from start
     45static inline std::string &ltrim(std::string &s)
     46{
     47    s.erase(s.begin(),
     48        std::find_if(s.begin(), s.end(),
     49                     std::not1(std::ptr_fun<int, int>(std::isspace))));
     50    return s;
     51}
     52
     53// Trim from end
     54static inline std::string &rtrim(std::string &s)
     55{
     56    s.erase(std::find_if(s.rbegin(), s.rend(),
     57        std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
     58    return s;
     59}
     60
     61// Trim from both ends
     62static inline std::string &trim(std::string &s)
     63{
     64    return ltrim(rtrim(s));
     65}
     66
    4067extern "C" int
    4168RpUnits_Init(Tcl_Interp *interp)
     
    7198 * provided in -context option.
    7299 */
     100
    73101
    74102int
     
    208236    // or if we should use those provided in -context option
    209237
     238
     239    // Trim away white space from the value. 
     240    trim(inValue);
     241
    210242    double value;
    211     value = strtod(inValue.c_str(),&endptr);
     243    value = strtod(inValue.c_str(), &endptr);
    212244    if (endptr == inValue.c_str()) {
    213245        // there was no numeric value that could be pulled from inValue
Note: See TracChangeset for help on using the changeset viewer.