Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Multisplit/Tcl/multisplit-1.tcl
Normal file
5
Task/Multisplit/Tcl/multisplit-1.tcl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
proc simplemultisplit {text sep} {
|
||||
set map {}; foreach s $sep {lappend map $s "\uffff"}
|
||||
return [split [string map $map $text] "\uffff"]
|
||||
}
|
||||
puts [simplemultisplit "a!===b=!=c" {"==" "!=" "="}]
|
||||
14
Task/Multisplit/Tcl/multisplit-2.tcl
Normal file
14
Task/Multisplit/Tcl/multisplit-2.tcl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
proc multisplit {text sep} {
|
||||
foreach s $sep {lappend sr [regsub -all {\W} $s {\\&}]}
|
||||
set sepRE [join $sr "|"]
|
||||
set pieces {}
|
||||
set match {}
|
||||
set start 0
|
||||
while {[regexp -indices -start $start -- $sepRE $text found]} {
|
||||
lassign $found x y
|
||||
lappend pieces [string range $text $start [expr {$x-1}]]
|
||||
lappend match [lsearch -exact $sep [string range $text {*}$found]] $x
|
||||
set start [expr {$y + 1}]
|
||||
}
|
||||
return [list [lappend pieces [string range $text $start end]] $match]
|
||||
}
|
||||
5
Task/Multisplit/Tcl/multisplit-3.tcl
Normal file
5
Task/Multisplit/Tcl/multisplit-3.tcl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
set input "a!===b=!=c"
|
||||
set matchers {"==" "!=" "="}
|
||||
lassign [multisplit $input $matchers] substrings matchinfo
|
||||
puts $substrings
|
||||
puts $matchinfo
|
||||
Loading…
Add table
Add a link
Reference in a new issue