diff --git a/src/Common/StringParsing.fs b/src/Common/StringParsing.fs index a4e8d67f7..baedfc451 100644 --- a/src/Common/StringParsing.fs +++ b/src/Common/StringParsing.fs @@ -78,6 +78,26 @@ module String = if n = 0 || n % repeated.Length <> 0 then None else Some(n/repeated.Length, text.Substring(n, text.Length - n)) + /// Ignores everything until a end-line character is detected, returns the remaining string. + let (|SkipSingleLine|) (text:string) = + let rec tryEol eolList = + match eolList with + | h : string :: t -> + match text.IndexOf(h) with + | i when i < 0 -> tryEol t + | i -> + text.Substring (i + h.Length) + | _ -> + text + let result = tryEol [ "\r\n"; "\n" ] + let skipped = text.Substring(0, text.Length - result.Length) + if not <| String.IsNullOrWhiteSpace(skipped) then + FSharp.Formatting.Common.Log.warnf "skipped '%s' which contains non-whitespace character!" skipped + if result = text then + FSharp.Formatting.Common.Log.warnf "could not skip a line of %s, because no line-ending character was found!" text + result + + /// Matches when a string starts with a sub-string wrapped using the /// opening and closing sub-string specified in the parameter. /// For example "[aa]bc" is wrapped in [ and ] pair. Returns the wrapped diff --git a/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj b/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj index 3f20618a5..6b89954cf 100644 --- a/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj +++ b/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj @@ -93,6 +93,13 @@ + + + FSharp.Formatting.Common + {91bad90e-bf3b-4646-a1a7-1568f8f25075} + True + +