Commit babc50cb authored by Max Rottenkolber's avatar Max Rottenkolber
Browse files

Replaced external Q-ENCODE-P with proper SHOULD-ENCODE-P.

parent ae6a760b
......@@ -54,15 +54,19 @@ destructively."
(loop for buffer in (b-split string charset)
collect (usb8-array-to-base64-string buffer)))
(defun char-utf-8 (character)
"Return UTF-8 buffer for CHARACTER."
(string-to-octets (make-string 1 :initial-element character)
:encoding :utf-8))
(defun character-ascii (character)
"Return ASCII code for CHARACTER or NIL."
(let ((buffer (string-to-octets
(make-string 1 :initial-element character)
:encoding :utf-8)))
(when (= 1 (length buffer))
(unless (> #1=(aref buffer 0) *ascii-boundary*)
(defun q-encode-p (character)
"Predicate to test if CHARACTER needs to be q-encoded."
(let ((code (aref (char-utf-8 character) 0)))
(or (> code *ascii-boundary*)
(let ((code (character-ascii character)))
(or (not code)
(= code *ascii-newline*)
(= code *ascii-return*)
(= code *ascii-space*)
......@@ -70,6 +74,16 @@ destructively."
(= code *ascii-question-mark*)
(= code *ascii-underscore*))))
(defun should-encode-p (string)
"Predicate to test if STRING should be q encoded."
(when (find-if (lambda (char)
(let ((code (character-ascii char)))
(or (not code)
(= code *ascii-newline*)
(= code *ascii-return*))))
(defun q-encode-string (string charset)
"Return q encoded STRING using CHARSET."
(with-output-to-string (out)
......@@ -5,7 +5,7 @@
(:use :cl
(:export :q-encode-p
(:export :should-encode-p
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment