aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Giraud <manuel@ledu-giraud.fr>2019-06-07 12:18:16 +0200
committerStas Boukarev <stassats@gmail.com>2019-06-07 13:18:16 +0300
commit0d3826475133271ee8c590937136c1bc41b8cbe0 (patch)
treede19840e3bafd4001d7fbf1fb66dc61774889b8e
parent4661aba0faba908e63d1c1dbec035c855e834faf (diff)
downloadtl-who-0d3826475133271ee8c590937136c1bc41b8cbe0.tar.gz
tl-who-0d3826475133271ee8c590937136c1bc41b8cbe0.tar.bz2
tl-who-0d3826475133271ee8c590937136c1bc41b8cbe0.zip
downcase a tag only when it is in the same case (useful for some camel case XML tags).
-rw-r--r--specials.lisp6
-rw-r--r--util.lisp11
-rw-r--r--who.lisp6
3 files changed, 17 insertions, 6 deletions
diff --git a/specials.lisp b/specials.lisp
index 34d9689..cb0401c 100644
--- a/specials.lisp
+++ b/specials.lisp
@@ -63,8 +63,10 @@ can be defined as <input disabled>")
(defvar *downcase-tokens-p* t
"If NIL, a keyword symbol representing a tag or attribute name will
-not be automatically converted to lowercase. This is useful when one
-needs to output case sensitive XML.")
+not be automatically converted to lowercase. If T, the tag and
+attribute name will be converted to lowercase only if it is in the
+same case. This is useful when one needs to output case sensitive
+XML.")
(defvar *attribute-quote-char* #\'
"Quote character for attributes.")
diff --git a/util.lisp b/util.lisp
index f2b0993..17743fd 100644
--- a/util.lisp
+++ b/util.lisp
@@ -239,3 +239,14 @@ character set."
(eql (first form) 'cl:declare))
do (push form declarations)
finally (return (values (nreverse declarations) forms))))
+
+(defun same-case-p (string)
+ "Test if all characters of a string are in the same case."
+ (or (every #'(lambda (c) (or (not (alpha-char-p c)) (lower-case-p c))) string)
+ (every #'(lambda (c) (or (not (alpha-char-p c)) (upper-case-p c))) string)))
+
+(defun maybe-downcase (symbol)
+ (let ((string (string symbol)))
+ (if (and *downcase-tokens-p* (same-case-p string))
+ (string-downcase string)
+ string)))
diff --git a/who.lisp b/who.lisp
index 6315612..a1064f6 100644
--- a/who.lisp
+++ b/who.lisp
@@ -91,9 +91,7 @@ forms."
(declare (optimize speed space))
(loop with =var= = (gensym)
for (orig-attr . val) in attr-list
- for attr = (if *downcase-tokens-p*
- (string-downcase orig-attr)
- (string orig-attr))
+ for attr = (maybe-downcase orig-attr)
unless (null val) ;; no attribute at all if VAL is NIL
if (constantp val)
if (and *empty-attribute-syntax* (eq val t)) ; special case for SGML and HTML5
@@ -144,7 +142,7 @@ a list of strings or Lisp forms."))
"The standard method which is not specialized. The idea is that you
can use EQL specializers on the first argument."
(declare (optimize speed space))
- (let ((tag (if *downcase-tokens-p* (string-downcase tag) (string tag)))
+ (let ((tag (maybe-downcase tag))
(body-indent
;; increase *INDENT* by 2 for body -- or disable it
(when (and *indent* (not (member tag *html-no-indent-tags* :test #'string-equal)))