• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
        • Strtok!
        • Cases
        • Concatenation
        • Html-encoding
        • Character-kinds
        • Substrings
        • Strtok
        • Equivalences
        • Url-encoding
          • *url-encode-array*
          • Url-encode-chars-aux
          • Url-encode-char
            • Url-encode-chars
            • Url-encode-string
            • Url-encode-string-aux
            • Fast-url-encode-char
          • Lines
          • Ordering
          • Numbers
          • Pad-trim
          • Coercion
          • Std/strings-extensions
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/io
        • Std/osets
        • Std/system
        • Std/basic
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Url-encoding

    Url-encode-char

    URL encode a single character. (slow, logically nice version).

    Signature
    (url-encode-char x) → encoding
    Arguments
    x — Guard (characterp x).
    Returns
    encoding — Encoded version of X, in proper order.
        Type (character-listp encoding).

    See fast-url-encode-char for an faster, array-lookup alternative.

    Definitions and Theorems

    Function: url-encode-char

    (defun url-encode-char (x)
           (declare (xargs :guard (characterp x)))
           (let ((acl2::__function__ 'url-encode-char))
                (declare (ignorable acl2::__function__))
                (b* ((x (char-fix x))
                     ((when (or (and (char<= #\A x) (char<= x #\Z))
                                (and (char<= #\a x) (char<= x #\z))
                                (and (char<= #\0 x) (char<= x #\9))
                                (member x '(#\- #\_ #\. #\~))))
                      (list x))
                     (hex-code (nat-to-hex-chars (char-code x)))
                     (hex-code (if (eql (len hex-code) 1)
                                   (cons #\0 hex-code)
                                   hex-code)))
                    (cons #\% hex-code))))

    Theorem: character-listp-of-url-encode-char

    (defthm character-listp-of-url-encode-char
            (b* ((encoding (url-encode-char x)))
                (character-listp encoding))
            :rule-classes :rewrite)

    Theorem: url-encode-char-of-char-fix-x

    (defthm url-encode-char-of-char-fix-x
            (equal (url-encode-char (char-fix x))
                   (url-encode-char x)))

    Theorem: url-encode-char-chareqv-congruence-on-x

    (defthm url-encode-char-chareqv-congruence-on-x
            (implies (chareqv x x-equiv)
                     (equal (url-encode-char x)
                            (url-encode-char x-equiv)))
            :rule-classes :congruence)