Pad a string with spaces on the right.
(rpadstr x len) extends the string
(rpadchars "foo" 5) --> "foo "
This is completely dumb: we don't try to account for newlines, tabs, or
anything like that, and just add
If no new spaces are needed,
Function:
(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:
(defthm stringp-of-rpadstr (stringp (rpadstr x len)) :rule-classes :type-prescription)
Theorem:
(defthm len-of-explode-of-rpadstr (implies (force (stringp x)) (equal (len (explode (rpadstr x len))) (max (length x) (nfix len)))))
Theorem:
(defthm streqv-implies-equal-rpadstr-1 (implies (streqv x x-equiv) (equal (rpadstr x len) (rpadstr x-equiv len))) :rule-classes (:congruence))
Theorem:
(defthm istreqv-implies-istreqv-rpadstr-1 (implies (istreqv x x-equiv) (istreqv (rpadstr x len) (rpadstr x-equiv len))) :rule-classes (:congruence))