Posted to tcl by kostix at Mon Nov 09 13:26:46 GMT 2009view raw

  1. proc urls::encode_url {url} {
  2. set utf8_url [encoding convertto utf-8 $url]
  3. set len [string length $utf8_url]
  4. set encoded_url ""
  5. for {set i 0} {$i < $len} {incr i} {
  6. binary scan $utf8_url @${i}c sym
  7. set sym [expr {$sym & 0xFF}]
  8. if {$sym >= 128 || $sym <= 32} {
  9. append encoded_url [format "%%%02X" $sym]
  10. } else {
  11. append encoded_url [binary format c $sym]
  12. }
  13. }
  14. return $encoded_url
  15. }
  16.