@@ -45,7 +45,8 @@ foldl1 f (x::xs) = foldl f x xs
4545||| ```
4646partial
4747strHead : String -> Char
48−strHead = prim__strHead
48+strHead "" = idris_crash "Prelude.Strings: attempt to take the head of an empty string"
49+strHead x = prim__strHead x
4950
5051||| Returns the characters specified after the head of the string.
5152|||
@@ -59,7 +60,8 @@ strHead = prim__strHead
5960||| ```
6061partial
6162strTail : String -> String
62−strTail = prim__strTail
63+strTail "" = idris_crash "Prelude.Strings: attempt to take the tail of an empty string"
64+strTail xs = prim__strTail xs
6365
6466||| Adds a character to the front of the specified string.
6567|||
@@ -72,6 +74,18 @@ strTail = prim__strTail
7274strCons : Char -> String -> String
7375strCons = prim__strCons
7476
77+||| Returns the length of the string.
78+|||
79+||| ```idris example
80+||| length ""
81+||| ```
82+||| ```idris example
83+||| length "ABC"
84+||| ```
85+length : String -> Nat
86+length = fromInteger . prim__zextInt_BigInt . prim_lenString
87+
88+
7589||| Returns the nth character (starting from 0) of the specified string.
7690|||
7791||| Precondition: '0 < i < length s' for 'strIndex s i'.
@@ -81,7 +95,9 @@ strCons = prim__strCons
8195||| ```
8296partial
8397strIndex : String -> Int -> Char
84−strIndex = prim__strIndex
98+strIndex x i = if (i < 0 || i >= cast (length x))
99+ then idris_crash "Prelude.Strings: String index out of bounds"
100+ else prim__strIndex x i
85101
86102||| Reverses the elements within a String.
87103|||
@@ -297,17 +313,6 @@ unlines' (l::ls) = l ++ '\n' :: unlines' ls
297313unlines : List String -> String
298314unlines = pack . unlines' . map unpack
299315
300−||| Returns the length of the string.
301−|||
302−||| ```idris example
303−||| length ""
304−||| ```
305−||| ```idris example
306−||| length "ABC"
307−||| ```
308−length : String -> Nat
309−length = fromInteger . prim__zextInt_BigInt . prim_lenString
310−
311316||| Returns a substring of a given string
312317|||
313318||| @ index The (zero based) index of the string to extract. If this is