Created
March 6, 2020 06:27
-
-
Save yyamasak/c4eaf14755d65ff776a87018d22b2921 to your computer and use it in GitHub Desktop.
Convert string to unicode literal sequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package require unicode | |
proc to_unicode_literal {str} { | |
set cs [lmap c [unicode::fromstring $str] {format \\u%04x $c}] | |
join $cs "" | |
} | |
if {[namespace exists ::tk]} { | |
proc copy_to_clipboard {str} { | |
clipboard clear | |
clipboard append $str | |
} | |
proc to_literal {} { | |
global istr ostr | |
set ostr [to_unicode_literal $istr] | |
copy_to_clipboard $ostr | |
} | |
proc from_literal {} { | |
global istr ostr | |
set istr [subst $ostr] | |
copy_to_clipboard $istr | |
} | |
entry .ei -textvariable istr -width 100 | |
button .bi -text "To Literal" -command "to_literal" | |
entry .eo -textvariable ostr | |
button .bo -text "From Literal" -command "from_literal" | |
grid .ei .bi -sticky news | |
grid .eo .bo -sticky news | |
grid columnconfigure . 0 -weight 1 | |
grid columnconfigure . 1 -weight 0 | |
} else { | |
set str [lindex $argv 0] | |
to_unicode_literal $str | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Standalone executable is here.
https://yusuke-blog.info/wp-content/uploads/2020/03/unicode_literal_converter.zip