ad_decode (public)

 ad_decode value [ args... ]

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

This procedure is analogous to sql decode procedure. The first parameter is the value we want to decode. This parameter is followed by a list of pairs where first element in the pair is convert from value and second element is convert to value. The last value is default value, which will be returned in the case convert from values matches the given value to be decoded. Note that in most cases native Tcl idioms such as expr or switch will do the trick. This proc CAN make sense when one has many alternatives to decode, as in such cases a switch statement would not be as compact.

Good usage:
ad_decode $value f Foo b Bar d Dan s Stan l Lemon m Melon Unknown
---> a oneliner as opposed to a long switch statement

Bad usage:
ad_decode $boolean_p t 0 1
---> just use expr {!$boolean_p}

Parameters:
value (required)
input value
Returns:
matched value or default

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_decode ad_decode (test acs-tcl) ad_decode ad_decode test_ad_decode->ad_decode test_datamodel__named_constraints datamodel__named_constraints (test acs-tcl) test_datamodel__named_constraints->ad_decode Class ::xowf::test_item::Answer_manager Class ::xowf::test_item::Answer_manager (public) Class ::xowf::test_item::Answer_manager->ad_decode Class ::xowiki::includelet::book Class ::xowiki::includelet::book (public) Class ::xowiki::includelet::book->ad_decode Class ::xowiki::includelet::toc Class ::xowiki::includelet::toc (public) Class ::xowiki::includelet::toc->ad_decode acs_admin::posture_status acs_admin::posture_status (private) acs_admin::posture_status->ad_decode bm_delete_permission_p bm_delete_permission_p (public) bm_delete_permission_p->ad_decode

Testcases:
ad_decode, datamodel__named_constraints
Source code:
    set num_args [llength $args]
    if {$num_args % 2 == 1} {
        set default [lindex $args end]
        set map [lrange $args 0 end-1]
    } else {
        set default ""
        set map $args
    }
    if {[dict exists $map $value]} {
        return [dict get $map $value]
    } else {
        return $default
    }
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: