@@ -23,15 +23,15 @@ module String =
2323
2424 /// Matches when a string starts with the specified sub-string
2525 let (| StartsWith | _ |) ( start : string ) ( text : string ) =
26- if text.StartsWith( start) then
26+ if text.StartsWith( start, StringComparison.Ordinal ) then
2727 Some( text.Substring( start.Length))
2828 else
2929 None
3030
3131 /// Matches when a string starts with the specified sub-string
3232 /// The matched string is trimmed from all whitespace.
3333 let (| StartsWithTrim | _ |) ( start : string ) ( text : string ) =
34- if text.StartsWith( start) then
34+ if text.StartsWith( start, StringComparison.Ordinal ) then
3535 Some( text.Substring( start.Length) .Trim())
3636 else
3737 None
@@ -40,8 +40,8 @@ module String =
4040 /// with a given value (and returns the rest of it)
4141 let (| StartsAndEndsWith | _ |) ( starts : string , ends : string ) ( s : string ) =
4242 if
43- s.StartsWith( starts)
44- && s.EndsWith( ends)
43+ s.StartsWith( starts, StringComparison.Ordinal )
44+ && s.EndsWith( ends, StringComparison.Ordinal )
4545 && s.Length >= starts.Length + ends.Length
4646 then
4747 Some( s.Substring( starts.Length, s.Length - starts.Length - ends.Length))
@@ -60,8 +60,8 @@ module String =
6060 /// For example "[aa]bc" is wrapped in [ and ] pair. Returns the wrapped
6161 /// text together with the rest.
6262 let (| StartsWithWrapped | _ |) ( starts : string , ends : string ) ( text : string ) =
63- if text.StartsWith( starts) then
64- let id = text.IndexOf( ends, starts.Length)
63+ if text.StartsWith( starts, StringComparison.Ordinal ) then
64+ let id = text.IndexOf( ends, starts.Length, StringComparison.Ordinal )
6565
6666 if id >= 0 then
6767 let wrapped = text.Substring( starts.Length, id - starts.Length)
@@ -79,7 +79,7 @@ module String =
7979 let rec tryEol eolList =
8080 match eolList with
8181 | h: string :: t ->
82- match text.IndexOf( h) with
82+ match text.IndexOf( h, StringComparison.Ordinal ) with
8383 | i when i < 0 -> tryEol t
8484 | i -> text.Substring( i + h.Length)
8585 | _ -> text
@@ -174,15 +174,15 @@ module StringPosition =
174174 StartColumn = n.StartColumn + text.Length - trimmed.Length })
175175
176176 /// Matches when a string starts with any of the specified sub-strings
177- let (| StartsWithAny | _ |) ( starts : seq < string > ) ( text : string , _n : MarkdownRange ) =
178- if starts |> Seq.exists ( text.StartsWith) then
177+ let (| StartsWithAny | _ |) ( starts : string seq ) ( text : string , _n : MarkdownRange ) =
178+ if starts |> Seq.exists ( fun s -> text.StartsWith( s , StringComparison.Ordinal ) ) then
179179 Some()
180180 else
181181 None
182182
183183 /// Matches when a string starts with the specified sub-string
184184 let (| StartsWith | _ |) ( start : string ) ( text : string , n : MarkdownRange ) =
185- if text.StartsWith( start) then
185+ if text.StartsWith( start, StringComparison.Ordinal ) then
186186 Some(
187187 text.Substring( start.Length),
188188 { n with
@@ -194,7 +194,7 @@ module StringPosition =
194194 /// Matches when a string starts with the specified sub-string
195195 /// The matched string is trimmed from all whitespace.
196196 let (| StartsWithTrim | _ |) ( start : string ) ( text : string , n : MarkdownRange ) =
197- if text.StartsWith( start) then
197+ if text.StartsWith( start, StringComparison.Ordinal ) then
198198 Some(
199199 text.Substring( start.Length) .Trim(),
200200 { n with
@@ -207,7 +207,7 @@ module StringPosition =
207207 /// The matched string is trimmed from all whitespace.
208208 let (| StartsWithNTimesTrimIgnoreStartWhitespace | _ |) ( start : string ) ( text : string , _n : MarkdownRange ) =
209209 if text.Contains( start) then
210- let beforeStart = text.Substring( 0 , text.IndexOf( start))
210+ let beforeStart = text.Substring( 0 , text.IndexOf( start, StringComparison.Ordinal ))
211211
212212 if String.IsNullOrWhiteSpace( beforeStart) then
213213 let startAndRest = text.Substring( beforeStart.Length)
@@ -232,8 +232,8 @@ module StringPosition =
232232 /// with a given value (and returns the rest of it)
233233 let (| StartsAndEndsWith | _ |) ( starts : string , ends : string ) ( s : string , n : MarkdownRange ) =
234234 if
235- s.StartsWith( starts)
236- && s.EndsWith( ends)
235+ s.StartsWith( starts, StringComparison.Ordinal )
236+ && s.EndsWith( ends, StringComparison.Ordinal )
237237 && s.Length >= starts.Length + ends.Length
238238 then
239239 Some(
@@ -276,8 +276,8 @@ module StringPosition =
276276 /// For example "[aa]bc" is wrapped in [ and ] pair. Returns the wrapped
277277 /// text together with the rest.
278278 let (| StartsWithWrapped | _ |) ( starts : string , ends : string ) ( text : string , n : MarkdownRange ) =
279- if text.StartsWith( starts) then
280- let id = text.IndexOf( ends, starts.Length)
279+ if text.StartsWith( starts, StringComparison.Ordinal ) then
280+ let id = text.IndexOf( ends, starts.Length, StringComparison.Ordinal )
281281
282282 if id >= 0 then
283283 let wrapped = text.Substring( starts.Length, id - starts.Length)
@@ -299,7 +299,7 @@ module StringPosition =
299299 /// complete repetitions of a specified sub-string.
300300 let (| EqualsRepeated | _ |) ( repeated , _n : MarkdownRange ) =
301301 function
302- | StartsWithRepeated repeated (_ n, ( " " , _)) -> Some()
302+ | StartsWithRepeated repeated (_ n, ( v , _)) when ( String.IsNullOrWhiteSpace v ) -> Some()
303303 | _ -> None
304304
305305module List =
@@ -363,7 +363,8 @@ module Lines =
363363 let (| TakeStartingWithOrBlank | _ |) ( start : string ) ( input : string list ) =
364364 match
365365 input
366- |> List.partitionWhile ( fun s -> String.IsNullOrWhiteSpace s || s.StartsWith( start))
366+ |> List.partitionWhile ( fun s ->
367+ String.IsNullOrWhiteSpace s || s.StartsWith( start, StringComparison.Ordinal))
367368 with
368369 | matching, rest when matching <> [] -> Some( matching, rest)
369370 | _ -> None
@@ -405,7 +406,7 @@ module Lines =
405406 |> List.map ( fun ( StringPosition.TrimStart s ) -> s)
406407 // Now remove all additional spaces at the end, but keep two spaces if existent
407408 |> List.map ( fun ( s , n ) ->
408- let endsWithTwoSpaces = s.EndsWith( " " )
409+ let endsWithTwoSpaces = s.EndsWith( " " , StringComparison.Ordinal )
409410
410411 let trimmed = s.TrimEnd([| ' ' |]) + if endsWithTwoSpaces then " " else " "
411412
0 commit comments