Forum OpenACS Q&A: Response to Non Greedy Regexp for Tag Substitution

Collapse
Posted by Jerry Asher on
Uh, the final proc had some html encoded values that the roundtrip through bboard just decoded. Therefore it is thus this:
proc blog_glossary_merge {message} {
    if {[nsv_exists blog_glossary init]} {
        set counter 0
        while {[regexp -indices {::(.*?)::} $message match iphrase]} {
            set phrase [string range $message [lindex $iphrase 0] [lindex $iphrase 1]]
            # ns_log notice found phrase $phrase
            if {[empty_string_p $phrase]} {
                set value "::"
            } else {
                if {[nsv_exists blog_glossary $phrase]} {
                    set value " [nsv_get blog_glossary $phrase] "
                } else {
                    set value "::${phrase}::"
                }
            }
            # ns_log notice value is $value
            set newmessage [string replace $message [expr [lindex $iphrase 0] - 2] [expr [lindex $iphrase 1] + 2] $value]
            # ns_log notice message is now $message
            # ns_log notice newmessage is now $newmessage
            set message $newmessage
            incr counter
        }
    } else {
        set fault "
        <center><table border=1 bgcolor=mistyrose cellpadding=10><tr><td>
        The global shortcuts glossary is down, sorry</td></tr></table></center>
        "
        error $fault
    }
    return $message
}