• 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

    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)