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

    Lpadstr

    Pad a string with spaces on the left.

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

    (lpadstr "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 is performed.

    Definitions and Theorems

    Function: lpadstr

    (defun
     lpadstr (x len)
     (declare (xargs :guard (and (stringp x) (natp len)))
              (type string x)
              (type integer len))
     (mbe
       :logic (implode (lpadchars (explode x) len))
       :exec (let* ((x-len (length x))
                    (diff (- len x-len)))
                   (if (< 0 diff)
                       (implode (make-list-ac diff #\Space (explode x)))
                       x))))

    Theorem: stringp-of-lpadstr

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

    Theorem: len-of-explode-of-lpadstr

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

    Theorem: streqv-implies-equal-lpadstr-1

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

    Theorem: istreqv-implies-istreqv-lpadstr-1

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