Changeset 1578 for trunk


Ignore:
Timestamp:
Oct 9, 2009, 7:53:42 AM (15 years ago)
Author:
mmc
Message:

Changed the new Rappture::split command to Rappture::slice. George found
problems in other Rappture:: routines that were accidentally using the
Rappture version of split, which does a slightly different thing.

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

Legend:

Unmodified
Added
Removed
  • trunk/lang/tcl/src/Makefile.in

    r1576 r1578  
    5656                RpRusage.o \
    5757                RpSignal.o  \
    58                 RpSplit.o  \
     58                RpSlice.o  \
    5959                RpSysinfo.o  \
    6060                Switch.o \
  • trunk/lang/tcl/src/Rappture_Init.c

    r1576 r1578  
    7474        return TCL_ERROR;
    7575    }
    76     if (RpSplit_Init(interp) != TCL_OK) {
     76    if (RpSlice_Init(interp) != TCL_OK) {
    7777        return TCL_ERROR;
    7878    }
  • trunk/lang/tcl/src/RpSlice.c

    r1576 r1578  
    11/*
    22 * ----------------------------------------------------------------------
    3  *  Rappture::split
     3 *  Rappture::slice
    44 *
    55 *  This is similar to the usual Tcl "split" command, in that it
     
    1212 *
    1313 *  EXAMPLES:
    14  *    Rappture::split -open { -close } -separators ", \t\n" $string
    15  *    Rappture::split -open \" -close \" -separators ", " $string
     14 *    Rappture::slice -open { -close } -separators ", \t\n" $string
     15 *    Rappture::slice -open \" -close \" -separators ", " $string
    1616 *
    1717 * ======================================================================
     
    2626#include <string.h>
    2727
    28 static Tcl_ObjCmdProc RpSplitCmd;
     28static Tcl_ObjCmdProc RpSliceCmd;
    2929
    3030/*
    3131 * ------------------------------------------------------------------------
    32  *  RpSplit_Init()
     32 *  RpSlice_Init()
    3333 *
    3434 *  Called in Rappture_Init() to initialize the commands defined
     
    3737 */
    3838int
    39 RpSplit_Init(interp)
     39RpSlice_Init(interp)
    4040    Tcl_Interp *interp;  /* interpreter being initialized */
    4141{
    42     Tcl_CreateObjCommand(interp, "::Rappture::split", RpSplitCmd, NULL, NULL);
     42    Tcl_CreateObjCommand(interp, "::Rappture::slice", RpSliceCmd, NULL, NULL);
    4343    return TCL_OK;
    4444}
     
    4646/*
    4747 * ------------------------------------------------------------------------
    48  *  RpSplitCmd()
    49  *
    50  *  Invoked whenever someone uses the "split" command to split a string
     48 *  RpSliceCmd()
     49 *
     50 *  Invoked whenever someone uses the "slice" command to slice a string
    5151 *  into multiple components.  Handles the following syntax:
    5252 *
    53  *      split ?-open <char>? ?-close <char>? ?-separators <abc>? <string>
     53 *      slice ?-open <char>? ?-close <char>? ?-separators <abc>? <string>
    5454 *
    5555 *  Returns TCL_OK on success, and TCL_ERROR (along with an error
     
    5858 */
    5959static int
    60 RpSplitCmd(cdata, interp, objc, objv)
     60RpSliceCmd(cdata, interp, objc, objv)
    6161    ClientData cdata;         /* not used */
    6262    Tcl_Interp *interp;       /* interpreter handling this request */
  • trunk/lang/tcl/tests/slice.test

    r1576 r1578  
    1 # Commands covered: Rappture::split
     1# Commands covered: Rappture::slice
    22#
    33# This file contains a collection of tests for one of the Rappture Tcl
     
    2222# Check command line switches and proper args
    2323#----------------------------------------------------------
    24 test split-1.1 {requires at least one arg} {
    25     list [catch {Rappture::split} msg] $msg
    26 } {1 {wrong # args: should be "Rappture::split ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
     24test slice-1.1 {requires at least one arg} {
     25    list [catch {Rappture::slice} msg] $msg
     26} {1 {wrong # args: should be "Rappture::slice ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
    2727
    28 test split-1.2 {has certain options} {
    29     list [catch {Rappture::split -foo string} msg] $msg
     28test slice-1.2 {has certain options} {
     29    list [catch {Rappture::slice -foo string} msg] $msg
    3030} {1 {bad option "-foo": should be -open, -close, -separators, --}}
    3131
    32 test split-1.3 {options require values} {
    33     list [catch {Rappture::split -separators string} msg] $msg
    34 } {1 {wrong # args: should be "Rappture::split ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
     32test slice-1.3 {options require values} {
     33    list [catch {Rappture::slice -separators string} msg] $msg
     34} {1 {wrong # args: should be "Rappture::slice ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
    3535
    36 test split-1.4 {open/close quote lists must match} {
    37     list [catch {Rappture::split -open 1 -close 12 string} msg] $msg
     36test slice-1.4 {open/close quote lists must match} {
     37    list [catch {Rappture::slice -open 1 -close 12 string} msg] $msg
    3838} {1 {must have same number of quote characters for -open and -close}}
    3939
    40 test split-1.5 {can't have multiple strings} {
    41     list [catch {Rappture::split -separators ab string1 string2} msg] $msg
    42 } {1 {wrong # args: should be "Rappture::split ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
     40test slice-1.5 {can't have multiple strings} {
     41    list [catch {Rappture::slice -separators ab string1 string2} msg] $msg
     42} {1 {wrong # args: should be "Rappture::slice ?-open chars? ?-close chars? ?-separators chars? ?--? string}}
    4343
    44 test split-1.6 {use -- when string starts with -} {
    45     list [catch {Rappture::split -- "-foo -bar"} msg] $msg
     44test slice-1.6 {use -- when string starts with -} {
     45    list [catch {Rappture::slice -- "-foo -bar"} msg] $msg
    4646} {0 {-foo -bar}}
    4747
     
    4949# Check the rules for splitting
    5050#----------------------------------------------------------
    51 test split-2.1 {multiple separator chars are lumped together} {
    52     Rappture::split -separators ", \t\n" "one,  two ,  three  "
     51test slice-2.1 {multiple separator chars are lumped together} {
     52    Rappture::slice -separators ", \t\n" "one,  two ,  three  "
    5353} {one two three}
    5454
    55 test split-2.2 {leading separators are ignored} {
    56     Rappture::split -separators ", \t\n" ",, one,  two,"
     55test slice-2.2 {leading separators are ignored} {
     56    Rappture::slice -separators ", \t\n" ",, one,  two,"
    5757} {one two}
    5858
    59 test split-2.3 {quote characters keep things together} {
    60     Rappture::split -open \" -close \" {"foo bar" "baz"  " qux "}
     59test slice-2.3 {quote characters keep things together} {
     60    Rappture::slice -open \" -close \" {"foo bar" "baz"  " qux "}
    6161} {{foo bar} baz { qux }}
    6262
    63 test split-2.4 {embedded quotes are ignored} {
    64     Rappture::split -open \" -close \" {foo"bar "baz\""  \"qux}
     63test slice-2.4 {embedded quotes are ignored} {
     64    Rappture::slice -open \" -close \" {foo"bar "baz\""  \"qux}
    6565} {foo\"bar {baz\"} {\"qux}}
    6666
    67 test split-2.5 {trailing quote doesn't dump core} {
    68     Rappture::split -open \" -close \" {foo"bar "baz"  \"qux "}
     67test slice-2.5 {trailing quote doesn't dump core} {
     68    Rappture::slice -open \" -close \" {foo"bar "baz"  \"qux "}
    6969} {foo\"bar baz {\"qux} {}}
    7070
    71 test split-2.6 {close quote corresponds to open quote} {
    72     Rappture::split -open \"< -close \"> { <foo bar> <a b " c> "a<>b" }
     71test slice-2.6 {close quote corresponds to open quote} {
     72    Rappture::slice -open \"< -close \"> { <foo bar> <a b " c> "a<>b" }
    7373} {{foo bar} {a b " c} a<>b}
    7474
    75 test split-2.7 {close quote can be escaped} {
    76     Rappture::split -open \"< -close \"> { <<foo bar\>> <a  b> }
     75test slice-2.7 {close quote can be escaped} {
     76    Rappture::slice -open \"< -close \"> { <<foo bar\>> <a  b> }
    7777} {{<foo bar\>} {a  b}}
    7878
    79 test split-2.8 {can override standard separators} {
    80     Rappture::split -separators : { 1eV : 2 eV : 0.1}
     79test slice-2.8 {can override standard separators} {
     80    Rappture::slice -separators : { 1eV : 2 eV : 0.1}
    8181} {{ 1eV } { 2 eV } { 0.1}}
    8282
    83 test split-2.9 {no quotes by default} {
    84     Rappture::split -separators : { "1eV : 2 eV" : 0.1}
     83test slice-2.9 {no quotes by default} {
     84    Rappture::slice -separators : { "1eV : 2 eV" : 0.1}
    8585} {{ "1eV } { 2 eV" } { 0.1}}
    8686
Note: See TracChangeset for help on using the changeset viewer.