Posted to tcl by kostix at Mon Nov 09 13:26:46 GMT 2009view raw
- proc urls::encode_url {url} {
- set utf8_url [encoding convertto utf-8 $url]
- set len [string length $utf8_url]
- set encoded_url ""
- for {set i 0} {$i < $len} {incr i} {
- binary scan $utf8_url @${i}c sym
- set sym [expr {$sym & 0xFF}]
- if {$sym >= 128 || $sym <= 32} {
- append encoded_url [format "%%%02X" $sym]
- } else {
- append encoded_url [binary format c $sym]
- }
- }
- return $encoded_url
- }