xowf::test_item::Question_manager method percent_substitute (protected)
<instance of xowf::test_item::Question_manager> percent_substitute \ [ -verbose ] [ -substvalues substvalues ] [ -seed seed ] text
Defined in packages/xowf/tcl/test-item-procs.tcl
- Switches:
- -verbose (optional)
- -substvalues (optional)
- -seed (optional)
- Parameters:
- text (required)
- Testcases:
- No testcase defined.
Source code: set result "" set start 0 foreach {p0 p1 p2} [regexp -all -inline -indices {%([a-zA-Z0-9_]+)[.]?([a-zA-Z0-9_]*)%} $text] { lassign $p0 first last set match [string range $text $first $last] set m1 [string range $text {*}$p1] set m2 [string range $text {*}$p2] if {[dict exists $substvalues $m1]} { set values [dict get $substvalues $m1] if {[info exists seed]} { set index [::xowiki::randomized_index -seed $seed [llength $values]] #ns_log notice "XXX percent_substitute called with seed <$seed> -> index $index <[llength $values]>" set value [lindex $values $index] } else { set value [lindex $values 0] } if {$m2 ne "" && [dict exists $value $m2]} { set value [dict get $value $m2] if {$verbose} { #ns_log notice "XXX percent_substitute chooses '$value' for $m2 from <$values>" } } set replacement $value } else { set replacement '$match' } append result [string range $text $start $first-1] $replacement set start [incr last] } append result [string range $text $start [string length $text]] return $resultXQL Not present: Generic, PostgreSQL, Oracle