• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • Std/strings
            • Pretty-printing
            • Printtree
            • Base64
            • Charset-p
            • Strtok!
            • Cases
            • Concatenation
            • Html-encoding
            • Character-kinds
            • Substrings
            • Strtok
              • Strtok-aux
            • Equivalences
            • Url-encoding
            • Lines
            • Explode-implode-equalities
            • Ordering
            • Numbers
            • Pad-trim
            • Coercion
            • Std/strings/digit-to-char
            • Substitution
            • Symbols
          • String-listp
          • Stringp
          • Length
          • Search
          • Remove-duplicates
          • Position
          • Coerce
          • Concatenate
          • Reverse
          • String
          • Subseq
          • Substitute
          • String-upcase
          • String-downcase
          • Count
          • Char
          • String<
          • String-equal
          • String-utilities
          • String-append
          • String>=
          • String<=
          • String>
          • Hex-digit-char-theorems
          • String-downcase-gen
          • String-upcase-gen
        • Program-wrapper
        • Get-internal-time
        • Basics
        • Packages
        • Oracle-eval
        • Defmacro-untouchable
        • <<
        • Primitive
        • Revert-world
        • Unmemoize
        • Set-duplicate-keys-action
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Fake-oracle-eval
        • Defopen
        • Sleep
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Std/strings

Strtok

Tokenize a string with character delimiters.

(strtok x delimiters) splits the string x into a list of substrings, based on delimiters, a list of characters. This is somewhat similar to repeatedly calling the strtok function in C.

As an example:

(strtok "foo bar, baz!" (list #\Space #\, #\!))
  -->
("foo" "bar" "baz")

Note that all of the characters in delimiters are removed, and no empty strings are ever found in strtok's output.

Definitions and Theorems

Function: strtok$inline

(defun strtok$inline (x delimiters)
  (declare (xargs :guard (and (stringp x)
                              (character-listp delimiters))))
  (let ((rtokens (strtok-aux x 0
                             (mbe :logic (len (explode x))
                                  :exec (length x))
                             delimiters nil nil)))
    (mbe :logic (rev rtokens)
         :exec (reverse rtokens))))

Theorem: string-listp-of-strtok

(defthm string-listp-of-strtok
  (string-listp (strtok x delimiters)))

Theorem: streqv-implies-equal-strtok-1

(defthm streqv-implies-equal-strtok-1
  (implies (streqv x x-equiv)
           (equal (strtok x delimiters)
                  (strtok x-equiv delimiters)))
  :rule-classes (:congruence))

Subtopics

Strtok-aux
Fast implementation of strtok.