Posted to tcl by evilotto at Thu Aug 22 20:12:54 GMT 2013view raw

  1. package require critcl
  2.  
  3. critcl::cproc mkbad {Tcl_Interp* i char* st} void {
  4. Tcl_DString d;
  5. char *end=st+strlen(st);
  6. Tcl_DStringInit(&d);
  7. do {
  8. char *n=Tcl_UtfNext(st);
  9. Tcl_DStringAppend(&d, st, n-st);
  10. st=n;
  11. } while (st<end);
  12. Tcl_DStringResult(i,&d);
  13. Tcl_DStringFree(&d);
  14. }
  15.  
  16. set a [mkbad ""]
  17. set b "\0"
  18.  
  19. puts [expr {$a ne $b}]
  20. puts [expr {[binary encode hex $a] eq [binary encode hex $b]}]
  21.  
  22. puts [string length $a]
  23. puts [string length $b]
  24.  
  25. puts [tcl::unsupported::representation $a]
  26. puts [tcl::unsupported::representation $b]