1- namespace Microsoft.FSharp.Compiler.SourceCodeServices
1+ // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+ namespace Microsoft.FSharp.Compiler.SourceCodeServices
24
35open System
46open System.Diagnostics
@@ -7,98 +9,6 @@ open Microsoft.FSharp.Compiler
79open Microsoft.FSharp .Compiler .Ast
810open Microsoft.FSharp .Compiler .Range
911open Microsoft.FSharp .Compiler .SourceCodeServices
10-
11- [<RequireQualifiedAccess>]
12- [<CompilationRepresentation( CompilationRepresentationFlags.ModuleSuffix) >]
13- module Array =
14- /// pass an array byref to reverse it in place
15- let revInPlace ( array : 'T []) =
16- if Array.isEmpty arraythen () else
17- let arrlen , revlen = array.Length-1 , array.Length/ 2 - 1
18- for idxin 0 .. revlendo
19- let t1 = array.[ idx]
20- let t2 = array.[ arrlen- idx]
21- array.[ idx] <- t2
22- array.[ arrlen- idx] <- t1
23-
24- /// Async implementation of Array.map.
25- let mapAsync ( mapping : 'T -> Async < 'U >) ( array : 'T []) : Async < 'U []> =
26- let len = Array.length array
27- let result = Array.zeroCreate len
28-
29- async { // Apply the mapping function to each array element.
30- for iin 0 .. len- 1 do
31- let! mappedValue = mapping array.[ i]
32- result.[ i] <- mappedValue
33-
34- // Return the completed results.
35- return result
36- }
37-
38- [<RequireQualifiedAccess>]
39- [<CompilationRepresentation( CompilationRepresentationFlags.ModuleSuffix) >]
40- module String =
41- open System.IO
42-
43- let inline toCharArray ( str : string ) = str.ToCharArray()
44-
45- let lowerCaseFirstChar ( str : string ) =
46- if String.IsNullOrEmpty str
47- || Char.IsLower( str, 0 ) then strelse
48- let strArr = toCharArray str
49- match Array.tryHead strArrwith
50- | None-> str
51- | Some c->
52- strArr.[ 0 ] <- Char.ToLower c
53- String( strArr)
54-
55- let extractTrailingIndex ( str : string ) =
56- match strwith
57- | null -> null , None
58- | _ ->
59- let charr = str.ToCharArray()
60- Array.revInPlace charr
61- let digits = Array.takeWhile Char.IsDigit charr
62- Array.revInPlace digits
63- String digits
64- |> function
65- | " " -> str, None
66- | index-> str.Substring( 0 , str.Length- index.Length), Some( int index)
67-
68- /// Remove all trailing and leading whitespace from the string
69- /// return null if the string is null
70- let trim ( value : string ) = if isNull valuethen null else value.Trim()
71-
72- /// Splits a string into substrings based on the strings in the array separators
73- let split options ( separator : string []) ( value : string ) =
74- if isNull valuethen null else value.Split( separator, options)
75-
76- let (| StartsWith | _ |) pattern value =
77- if String.IsNullOrWhiteSpace valuethen
78- None
79- elif value.StartsWith patternthen
80- Some()
81- else None
82-
83- let (| Contains | _ |) pattern value =
84- if String.IsNullOrWhiteSpace valuethen
85- None
86- elif value.Contains patternthen
87- Some()
88- else None
89-
90- let getLines ( str : string ) =
91- use reader= new StringReader( str)
92- [|
93- let line = ref( reader.ReadLine())
94- while not ( isNull! line) do
95- yield ! line
96- line:= reader.ReadLine()
97- if str.EndsWith( " \n " ) then
98- // last trailing space not returned
99- // http://stackoverflow.com/questions/19365404/stringreader-omits-trailing-linebreak
100- yield String.Empty
101- |]
10212
10313[<AutoOpen>]
10414module internal CodeGenerationUtils =