• Top
    • Documentation
    • Books
    • 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
          • Explode-implode-equalities
          • Ordering
          • Numbers
          • Pad-trim
          • Coercion
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/osets
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • 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)