• 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

    Trim-bag

    Remove particular characters from the front and end of a string.

    (trim-bag x bag) removes the characters in bag from the front and end of the string x.

    BOZO eventually make this efficient.

    Definitions and Theorems

    Function: trim-aux

    (defun trim-aux (x bag)
           (declare (xargs :guard (and (character-listp x)
                                       (character-listp bag))))
           (if (consp x)
               (if (member (car x) bag)
                   (trim-aux (cdr x) bag)
                   x)
               nil))

    Theorem: character-listp-of-trim-aux

    (defthm character-listp-of-trim-aux
            (implies (force (character-listp x))
                     (character-listp (trim-aux x bag))))

    Function: trim-bag

    (defun trim-bag (x bag)
           (declare (xargs :guard (and (stringp x)
                                       (character-listp bag))))
           (let* ((chars (explode x))
                  (chars (trim-aux chars bag))
                  (chars (reverse chars))
                  (chars (trim-aux chars bag))
                  (chars (reverse chars)))
                 (implode chars)))

    Theorem: stringp-of-trim-bag

    (defthm stringp-of-trim-bag
            (stringp (trim-bag x bag))
            :rule-classes :type-prescription)