diff options
author | Sean Allred <code@seanallred.com> | 2014-11-14 17:25:27 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-14 17:30:21 -0500 |
commit | 1e859ea6d9b5365f69f8dea5d690e6bee8350e7a (patch) | |
tree | 7f7da64a833f8c1c783b6d4977fc79f06d227d1d /sx-encoding.el | |
parent | 403c021d92bb036be5d95735bc1403056db3780b (diff) | |
parent | 22cc1b1b959761cda2ff2048dbaeba99cc094930 (diff) |
Merge branch 'master' into network-list
Conflicts:
sx-filter.el
sx-question.el
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. |