Fast implementation of strtok.
Function:
(defun strtok-aux (x n xl delimiters curr acc) (declare (type string x) (type (integer 0 *) n xl) (xargs :guard (and (stringp x) (natp xl) (natp n) (<= xl (length x)) (<= n xl) (character-listp delimiters) (character-listp curr) (string-listp acc)))) (if (mbe :logic (zp (- (nfix xl) (nfix n))) :exec (int= n xl)) (if curr (cons (rchars-to-string curr) acc) acc) (let* ((char1 (char x n)) (matchp (member char1 delimiters))) (strtok-aux (the string x) (the (integer 0 *) (+ 1 (lnfix n))) (the integer xl) delimiters (if matchp nil (cons char1 curr)) (if (and matchp curr) (cons (rchars-to-string curr) acc) acc)))))
Theorem:
(defthm true-listp-of-strtok-aux (implies (true-listp acc) (true-listp (strtok-aux x n xl delimiters curr acc))))
Theorem:
(defthm string-listp-of-strtok-aux (implies (string-listp acc) (string-listp (strtok-aux x n xl delimiters curr acc))))
Theorem:
(defthm streqv-implies-equal-strtok-aux-1 (implies (streqv x x-equiv) (equal (strtok-aux x n xl delimiters curr acc) (strtok-aux x-equiv n xl delimiters curr acc))) :rule-classes (:congruence))