• 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
        • Lines
        • Explode-implode-equalities
        • Ordering
        • Numbers
        • Pad-trim
          • Rpadstr
            • Rpadchars
            • Lpadchars
            • Lpadstr
            • Trim-bag
            • 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
    • Pad-trim

    Rpadstr

    Pad a string with spaces on the right.

    (rpadstr x len) extends the string x to length len by adding spaces on the right. For instance,

    (rpadchars "foo" 5)
       -->
    "foo  "

    This is completely dumb: we don't try to account for newlines, tabs, or anything like that, and just add #\Space characters until reaching the desired width.

    If no new spaces are needed, x is returned unchanged and no consing or coercion is performed.

    Definitions and Theorems

    Function: rpadstr

    (defun rpadstr (x len)
      (declare (xargs :guard (and (stringp x) (natp len)))
               (type string x)
               (type integer len))
      (mbe :logic
           (implode (rpadchars (explode x) len))
           :exec
           (let* ((x-len (length (the string x)))
                  (diff (- len x-len)))
             (if (> diff 0)
                 (let ((spaces (repeat diff #\Space)))
                   (implode (mbe :logic (append-chars x spaces)
                                 :exec
                                 (if (zp x-len)
                                     spaces
                                   (append-chars-aux x (- x-len 1)
                                                     spaces)))))
               x))))

    Theorem: stringp-of-rpadstr

    (defthm stringp-of-rpadstr
      (stringp (rpadstr x len))
      :rule-classes :type-prescription)

    Theorem: len-of-explode-of-rpadstr

    (defthm len-of-explode-of-rpadstr
      (implies (force (stringp x))
               (equal (len (explode (rpadstr x len)))
                      (max (length x) (nfix len)))))

    Theorem: streqv-implies-equal-rpadstr-1

    (defthm streqv-implies-equal-rpadstr-1
      (implies (streqv x x-equiv)
               (equal (rpadstr x len)
                      (rpadstr x-equiv len)))
      :rule-classes (:congruence))

    Theorem: istreqv-implies-istreqv-rpadstr-1

    (defthm istreqv-implies-istreqv-rpadstr-1
      (implies (istreqv x x-equiv)
               (istreqv (rpadstr x len)
                        (rpadstr x-equiv len)))
      :rule-classes (:congruence))