//========================================================================= // (c) Microsoft Corporation 2005-2009. //========================================================================= namespace Microsoft.FSharp.Core open System.Diagnostics open Microsoft.FSharp.Core open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators open Microsoft.FSharp.Core.Operators open Microsoft.FSharp.Collections [] [] module String = let inline checkNonNull arg = match box arg with null -> nullArg "str" | _ -> () [] let concat sep (strings : seq) = System.String.Join(sep, Seq.to_array strings) [] let iter (f : (char -> unit)) (str:string) = checkNonNull str for i = 0 to str.Length - 1 do f str.[i] [] let iteri f (str:string) = checkNonNull str for i = 0 to str.Length - 1 do f i str.[i] [] let map (f: char -> char) (str:string) = checkNonNull str let res = new System.Text.StringBuilder(str.Length) str |> iter (fun c -> res.Append(f c) |> ignore); res.ToString() [] let mapi (f: int -> char -> char) (str:string) = checkNonNull str let res = new System.Text.StringBuilder(str.Length) str |> iteri (fun i c -> res.Append(f i c) |> ignore); res.ToString() [] let collect (f: char -> string) (str:string) = checkNonNull str let res = new System.Text.StringBuilder(str.Length) str |> iter (fun c -> res.Append(f c) |> ignore); res.ToString() [] let init (count:int) (f: int-> string) = if count < 0 then invalidArg "n" "the length may not be negative" let res = new System.Text.StringBuilder(count) for i = 0 to count - 1 do res.Append(f i) |> ignore; res.ToString() [] let replicate (count:int) (str:string) = checkNonNull str let res = new System.Text.StringBuilder(str.Length) for i = 0 to count - 1 do res.Append(str) |> ignore; res.ToString() [] let map_concat f str = collect f str [] let forall f (str:string) = checkNonNull str let rec check i = (i >= str.Length) || (f str.[i] && check (i+1)) check 0 [] let for_all f str = forall f str [] let exists f (str:string) = checkNonNull str let rec check i = (i < str.Length) && (f str.[i] || check (i+1)) check 0 [] let length (str:string) = checkNonNull str str.Length