template::template_tag_if_interp_expr (public)

 template::template_tag_if_interp_expr

Defined in packages/acs-templating/tcl/tag-procs.tcl

Interpret an expression as part of the simplified IF syntax

Partial Call Graph (max 5 caller/called nodes):
%3 template::template_tag_if_condition template::template_tag_if_condition (private) template::template_tag_if_interp_expr template::template_tag_if_interp_expr template::template_tag_if_condition->template::template_tag_if_interp_expr ad_log ad_log (public) template::template_tag_if_interp_expr->ad_log template::template_tag_subst_reference template::template_tag_subst_reference (private) template::template_tag_if_interp_expr->template::template_tag_subst_reference

Testcases:
No testcase defined.
Source code:

    upvar args args condition condition

    # append condition "\[expr "

    set op [lindex $args 1]

    if { $op eq "not" } {
        #
        # Optimize common case "@arg@ not nil"
        #
        set op [lindex $args 2]
        set arg1 \"[lindex $args 0]\"
        if {$op eq "nil" && [string first @ $arg1] > -1} {
            set arg1 [template_tag_subst_reference $arg1]
            append condition "(\[info exists $arg1\] && \${$arg1} ne {})"
            set args [lrange $args 3 end]
            return
        } else {
            append condition "! ("
            set close_paren ")"
        }
        set i 3
    } else {
        set close_paren ""
        set i 2
    }

    set arg1 "\"[lindex $args 0]\""

    # build the conditional expression

    switch -- $op {

        gt {
            append condition "$arg1 > \"[lindex $args $i]\""
            set next [expr {$i + 1}]
        }
        ge {
            append condition "$arg1 >= \"[lindex $args $i]\""
            set next [expr {$i + 1}]
        }
        lt {
            append condition "$arg1 <  \"[lindex $args $i]\""
            set next [expr {$i + 1}]
        }
        le {
            append condition "$arg1 <= \"[lindex $args $i]\""
            set next [expr {$i + 1}]
        }
        eq {
            append condition "$arg1 eq \"[lindex $args $i]\""
            set next [expr {$i + 1}]
        }
        ne {
            append condition "$arg1 ne \"[lindex $args $i]\""
            set next [expr {$i + 1}]
        }

        in {
            append condition "$arg1 in { [lrange $args 2 end] } "
            set next [llength $args]
        }

        between {
            set expr1 "$arg1 >= \"[lindex $args $i]\""
            set expr2 "$arg1 <= \"[lindex $args $i+1]\""
            append condition "($expr1 && $expr2)"
            set next [expr {$i + 2}]
        }

        nil {
            if { [string first @ $arg1] == -1 } {
                # We're assuming this is a static string, not a variable
                append condition "$arg1 eq {}"
            } else {
                set arg [template_tag_subst_reference $arg1]
                if {$arg eq ""} {
                    error "IF tag nil test uses string not variable for $arg1"
                }
                append condition "(!\[info exists $arg\] || \${$arg} eq {})"
            }
            set next $i
        }

        defined {
            set arg [template_tag_subst_reference $arg1]
            if {$arg eq ""} {
                error "IF tag nil test uses string not variable for $arg1"
            }
            append condition "\[info exists $arg\]"
            set next $i
        }

        odd {
            append condition "\[expr {$arg1 % 2}\]"
            set next $i
        }

        even {
            append condition "! \[expr {$arg1 % 2}\]"
            set next $i
        }

        true {
            #append condition "\[string is true -strict $arg1\]"
            append condition "\[string is true -strict $arg1\]"
            set next $i
        }

        false {
            append condition "!\[string is true -strict $arg1\]"
            set next $i
        }

        default {
            # treat <if @foo_p@> as a shortcut for <if @foo_p@ true>
            #append condition "\[string is true -strict $arg1\]"
            ad_log warning "operation <$op> in '$args' is using undocumented <if @foo_p@> as a shortcut for <if @foo_p@ true>"
            append condition "\[string is true -strict $arg1\]"
            set next [expr {$i - 1}]
        }
    }

    append condition $close_paren
    # append condition "]"

    set args [lrange $args $next end]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: