- Timestamp:
- Oct 9, 2009, 7:53:42 AM (15 years ago)
- Location:
- trunk/lang/tcl
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/tcl/src/Makefile.in
r1576 r1578 56 56 RpRusage.o \ 57 57 RpSignal.o \ 58 RpS plit.o \58 RpSlice.o \ 59 59 RpSysinfo.o \ 60 60 Switch.o \ -
trunk/lang/tcl/src/Rappture_Init.c
r1576 r1578 74 74 return TCL_ERROR; 75 75 } 76 if (RpS plit_Init(interp) != TCL_OK) {76 if (RpSlice_Init(interp) != TCL_OK) { 77 77 return TCL_ERROR; 78 78 } -
trunk/lang/tcl/src/RpSlice.c
r1576 r1578 1 1 /* 2 2 * ---------------------------------------------------------------------- 3 * Rappture::s plit3 * Rappture::slice 4 4 * 5 5 * This is similar to the usual Tcl "split" command, in that it … … 12 12 * 13 13 * EXAMPLES: 14 * Rappture::s plit-open { -close } -separators ", \t\n" $string15 * Rappture::s plit-open \" -close \" -separators ", " $string14 * Rappture::slice -open { -close } -separators ", \t\n" $string 15 * Rappture::slice -open \" -close \" -separators ", " $string 16 16 * 17 17 * ====================================================================== … … 26 26 #include <string.h> 27 27 28 static Tcl_ObjCmdProc RpS plitCmd;28 static Tcl_ObjCmdProc RpSliceCmd; 29 29 30 30 /* 31 31 * ------------------------------------------------------------------------ 32 * RpS plit_Init()32 * RpSlice_Init() 33 33 * 34 34 * Called in Rappture_Init() to initialize the commands defined … … 37 37 */ 38 38 int 39 RpS plit_Init(interp)39 RpSlice_Init(interp) 40 40 Tcl_Interp *interp; /* interpreter being initialized */ 41 41 { 42 Tcl_CreateObjCommand(interp, "::Rappture::s plit", RpSplitCmd, NULL, NULL);42 Tcl_CreateObjCommand(interp, "::Rappture::slice", RpSliceCmd, NULL, NULL); 43 43 return TCL_OK; 44 44 } … … 46 46 /* 47 47 * ------------------------------------------------------------------------ 48 * RpS plitCmd()49 * 50 * Invoked whenever someone uses the "s plit" command to splita string48 * RpSliceCmd() 49 * 50 * Invoked whenever someone uses the "slice" command to slice a string 51 51 * into multiple components. Handles the following syntax: 52 52 * 53 * s plit?-open <char>? ?-close <char>? ?-separators <abc>? <string>53 * slice ?-open <char>? ?-close <char>? ?-separators <abc>? <string> 54 54 * 55 55 * Returns TCL_OK on success, and TCL_ERROR (along with an error … … 58 58 */ 59 59 static int 60 RpS plitCmd(cdata, interp, objc, objv)60 RpSliceCmd(cdata, interp, objc, objv) 61 61 ClientData cdata; /* not used */ 62 62 Tcl_Interp *interp; /* interpreter handling this request */ -
trunk/lang/tcl/tests/slice.test
r1576 r1578 1 # Commands covered: Rappture::s plit1 # Commands covered: Rappture::slice 2 2 # 3 3 # This file contains a collection of tests for one of the Rappture Tcl … … 22 22 # Check command line switches and proper args 23 23 #---------------------------------------------------------- 24 test s plit-1.1 {requires at least one arg} {25 list [catch {Rappture::s plit} msg] $msg26 } {1 {wrong # args: should be "Rappture::s plit?-open chars? ?-close chars? ?-separators chars? ?--? string}}24 test 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}} 27 27 28 test s plit-1.2 {has certain options} {29 list [catch {Rappture::s plit-foo string} msg] $msg28 test slice-1.2 {has certain options} { 29 list [catch {Rappture::slice -foo string} msg] $msg 30 30 } {1 {bad option "-foo": should be -open, -close, -separators, --}} 31 31 32 test s plit-1.3 {options require values} {33 list [catch {Rappture::s plit-separators string} msg] $msg34 } {1 {wrong # args: should be "Rappture::s plit?-open chars? ?-close chars? ?-separators chars? ?--? string}}32 test 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}} 35 35 36 test s plit-1.4 {open/close quote lists must match} {37 list [catch {Rappture::s plit-open 1 -close 12 string} msg] $msg36 test slice-1.4 {open/close quote lists must match} { 37 list [catch {Rappture::slice -open 1 -close 12 string} msg] $msg 38 38 } {1 {must have same number of quote characters for -open and -close}} 39 39 40 test s plit-1.5 {can't have multiple strings} {41 list [catch {Rappture::s plit-separators ab string1 string2} msg] $msg42 } {1 {wrong # args: should be "Rappture::s plit?-open chars? ?-close chars? ?-separators chars? ?--? string}}40 test 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}} 43 43 44 test s plit-1.6 {use -- when string starts with -} {45 list [catch {Rappture::s plit-- "-foo -bar"} msg] $msg44 test slice-1.6 {use -- when string starts with -} { 45 list [catch {Rappture::slice -- "-foo -bar"} msg] $msg 46 46 } {0 {-foo -bar}} 47 47 … … 49 49 # Check the rules for splitting 50 50 #---------------------------------------------------------- 51 test s plit-2.1 {multiple separator chars are lumped together} {52 Rappture::s plit-separators ", \t\n" "one, two , three "51 test slice-2.1 {multiple separator chars are lumped together} { 52 Rappture::slice -separators ", \t\n" "one, two , three " 53 53 } {one two three} 54 54 55 test s plit-2.2 {leading separators are ignored} {56 Rappture::s plit-separators ", \t\n" ",, one, two,"55 test slice-2.2 {leading separators are ignored} { 56 Rappture::slice -separators ", \t\n" ",, one, two," 57 57 } {one two} 58 58 59 test s plit-2.3 {quote characters keep things together} {60 Rappture::s plit-open \" -close \" {"foo bar" "baz" " qux "}59 test slice-2.3 {quote characters keep things together} { 60 Rappture::slice -open \" -close \" {"foo bar" "baz" " qux "} 61 61 } {{foo bar} baz { qux }} 62 62 63 test s plit-2.4 {embedded quotes are ignored} {64 Rappture::s plit-open \" -close \" {foo"bar "baz\"" \"qux}63 test slice-2.4 {embedded quotes are ignored} { 64 Rappture::slice -open \" -close \" {foo"bar "baz\"" \"qux} 65 65 } {foo\"bar {baz\"} {\"qux}} 66 66 67 test s plit-2.5 {trailing quote doesn't dump core} {68 Rappture::s plit-open \" -close \" {foo"bar "baz" \"qux "}67 test slice-2.5 {trailing quote doesn't dump core} { 68 Rappture::slice -open \" -close \" {foo"bar "baz" \"qux "} 69 69 } {foo\"bar baz {\"qux} {}} 70 70 71 test s plit-2.6 {close quote corresponds to open quote} {72 Rappture::s plit-open \"< -close \"> { <foo bar> <a b " c> "a<>b" }71 test slice-2.6 {close quote corresponds to open quote} { 72 Rappture::slice -open \"< -close \"> { <foo bar> <a b " c> "a<>b" } 73 73 } {{foo bar} {a b " c} a<>b} 74 74 75 test s plit-2.7 {close quote can be escaped} {76 Rappture::s plit-open \"< -close \"> { <<foo bar\>> <a b> }75 test slice-2.7 {close quote can be escaped} { 76 Rappture::slice -open \"< -close \"> { <<foo bar\>> <a b> } 77 77 } {{<foo bar\>} {a b}} 78 78 79 test s plit-2.8 {can override standard separators} {80 Rappture::s plit-separators : { 1eV : 2 eV : 0.1}79 test slice-2.8 {can override standard separators} { 80 Rappture::slice -separators : { 1eV : 2 eV : 0.1} 81 81 } {{ 1eV } { 2 eV } { 0.1}} 82 82 83 test s plit-2.9 {no quotes by default} {84 Rappture::s plit-separators : { "1eV : 2 eV" : 0.1}83 test slice-2.9 {no quotes by default} { 84 Rappture::slice -separators : { "1eV : 2 eV" : 0.1} 85 85 } {{ "1eV } { 2 eV" } { 0.1}} 86 86
Note: See TracChangeset
for help on using the changeset viewer.