Skip to content

Instantly share code, notes, and snippets.

@ifree
Last active August 29, 2015 14:02
Show Gist options
  • Save ifree/55bc4c877cc09f44d0f5 to your computer and use it in GitHub Desktop.
Save ifree/55bc4c877cc09f44d0f5 to your computer and use it in GitHub Desktop.
convert hex or unicode encoded string to normal string
;(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