Library Coq.Strings.String
Contributed by Laurent Théry (INRIA);
Adapted to Coq V8 by the Coq Development Team
Definition of strings
Implementation of string as list of ascii characters
Equality is decidable
Length
Nth character of a string
Two lists that are identical through get are syntactically equal
The first elements of s1 ++ s2 are the ones of s1
The last elements of s1 ++ s2 are the ones of s2
Substrings
substring n m s returns the substring of
s that starts
at position
n and of length
m;
if this does not make sense it returns
""
Fixpoint substring (
n m :
nat) (
s :
string) :
string :=
match n,
m,
s with
| 0, 0,
_ =>
EmptyString
| 0,
S m´,
EmptyString =>
s
| 0,
S m´,
String c s´ =>
String c (
substring 0
m´ s´)
|
S n´,
_,
EmptyString =>
s
|
S n´,
_,
String c s´ =>
substring n´ m s´
end.
The substring is included in the initial string
The substring has at most m elements
Test functions
Test if
s1 is a prefix of
s2
If s1 is a prefix of s2, it is the substring of length
length s1 starting at position O of s2
Test if, starting at position n, s1 occurs in s2; if
so it returns the position
If the result of index is Some m, s1 in s2 at position m
If the result of index is Some m,
s1 does not occur in s2 before m
If the result of index is None, s1 does not occur in s2
after n
If we are searching for the Empty string and the answer is no
this means that n is greater than the size of s
Same as index but with no optional type, we return 0 when it
does not occur
Concrete syntax
The concrete syntax for strings in scope string_scope follows the
Coq convention for strings: all ascii characters of code less than
128 are litteral to the exception of the character `double quote'
which must be doubled.
Strings that involve ascii characters of code >= 128 which are not
part of a valid utf8 sequence of characters are not representable
using the Coq string notation (use explicitly the String constructor
with the ascii codes of the characters).