Last active
August 29, 2015 14:02
-
-
Save ifree/55bc4c877cc09f44d0f5 to your computer and use it in GitHub Desktop.
convert hex or unicode encoded string to normal string
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
;(decode-coding-string "keywork" 'utf-8) | |
(defun js2-unescape (b) | |
"convert hex or unicode encoded string to normal string" | |
(interactive "bselect buffer ") | |
(let* | |
((hex-pattern "\\\\x\\(\\w+\\)") | |
(unicode-pattern "\\\\u\\(\\w+\\)") | |
(process | |
#'(lambda (p) | |
(with-current-buffer b | |
(save-excursion | |
(goto-char (point-min)) | |
(while (search-forward-regexp p nil t) | |
(replace-match | |
(format "%c" (string-to-number (match-string 1) 16)) | |
nil t)) | |
))))) | |
(funcall process hex-pattern) | |
(funcall process unicode-pattern) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment