Skip to content

Commit

Permalink
Add is_substring
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGross committed Mar 2, 2025
1 parent 847d6a7 commit 2acd88d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Util/Strings/String.v
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,19 @@ Fixpoint strip_leading_newlines (s : list string) : list string

Definition strip_trailing_newlines (s : list string) : list string
:= List.rev_append (strip_leading_newlines (List.rev_append s nil)) nil.

(** [is_substring s1 s2] returns [true] if [s1] is a substring of [s2] *)
Definition is_substring (s1 s2 : string) : bool :=
if (s1 =? "")%string
then true
else
match split s1 s2 with
| nil => false
| _ :: nil => false
| _ :: _ :: _ => true
end.

Lemma is_substring_correct s1 s2 :
is_substring s1 s2 = true <-> exists n, substring n (String.length s1) s2 = s1.
Proof.
Abort.

0 comments on commit 2acd88d

Please sign in to comment.