diff options
author | Sean Allred <code@seanallred.com> | 2014-11-14 09:34:14 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-14 09:34:14 -0500 |
commit | 77e519de7b1219767a25399b727c2aece6189e6c (patch) | |
tree | 5c99eb09549561a549e93c19aaa788cd81a16073 /sx-encoding.el | |
parent | 525a304f9aca38e1101a1d02ade26ec3b8e91b23 (diff) | |
parent | 8d14a6b425d27b7b942f3922d583877ec8b00690 (diff) |
Merge pull request #46 from vermiculus/sx-question-mode
Question Mode
Diffstat (limited to 'sx-encoding.el')
-rw-r--r-- | sx-encoding.el | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sx-encoding.el b/sx-encoding.el index 0b72365..9d48e60 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -23,6 +23,8 @@ ;;; Code: +(require 'cl-lib) + (defcustom sx-encoding-html-entities-plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" Agrave "À" agrave "à" alefsym "ℵ" Alpha "Α" alpha "α" amp "&" and "∧" @@ -74,6 +76,39 @@ (substring ss 1)))))))) (replace-regexp-in-string "&[^; ]*;" get-function string))) +(defun sx-encoding-normalize-line-endings (string) + "Normalize the line endings for STRING" + (delete ?\r string)) + +(defun sx-encoding-clean-content (string) + "Cleans STRING for display. +Applies `sx-encoding-normalize-line-endings' and +`sx-encoding-decode-entities'." + (sx-encoding-decode-entities + (sx-encoding-normalize-line-endings + string))) + +(defun sx-encoding-clean-content-deep (data) + "Clean DATA recursively where necessary. + +See `sx-encoding-clean-content'." + (if (consp data) + ;; If we're looking at a cons cell, test to see if is a list. If + ;; it is, map ourselves over the entire list. If it is not, + ;; reconstruct the cons cell using a cleaned cdr. + (if (listp (cdr data)) + (cl-map #'list #'sx-encoding-clean-content-deep data) + (cons (car data) (sx-encoding-clean-content-deep (cdr data)))) + ;; If we're looking at an atom, clean and return if we're looking + ;; at a string, map if we're looking at a vector, and just return + ;; if we aren't looking at either. + (cond + ((stringp data) + (sx-encoding-clean-content data)) + ((vectorp data) + (cl-map #'vector #'sx-encoding-clean-content-deep data)) + (t data)))) + (defun sx-encoding-gzipped-p (data) "Checks for magic bytes in DATA. |