Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev16.1 to fsharp5 #6531

Merged
1 commit merged into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ These are the branches in use:
- Gets integrated into https://github.com/fsharp/FSharp.Compiler.Service to form the basis of FSharp.Compiler.Service releases

* `dev15.9`
- Servicing branch for VS 2019 update 15.9. We do not expect to service that release, but if we do, that's where the changes would go.
- Servicing branch for VS 2017 update 15.9. We do not expect to service that release, but if we do, that's where the changes would go.

* `dev16.x`
- Latest release branch for the particular point release of Visual Studio.
Expand Down
12 changes: 5 additions & 7 deletions src/fsharp/CheckFormatStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ let mkFlexibleDecimalFormatTypar (g: TcGlobals) m =
let mkFlexibleFloatFormatTypar (g: TcGlobals) m =
mkFlexibleFormatTypar m [ g.float_ty; g.float32_ty; g.decimal_ty ] g.float_ty

let isDigit c = ('0' <= c && c <= '9')

type FormatInfoRegister =
{ mutable leftJustify : bool
mutable numPrefixIfPos : char option
Expand Down Expand Up @@ -117,13 +115,13 @@ let parseFormatStringInternal (m:range) (g: TcGlobals) (context: FormatStringChe
let rec digitsPrecision i =
if i >= len then failwithf "%s" <| FSComp.SR.forBadPrecision()
match fmt.[i] with
| c when isDigit c -> digitsPrecision (i+1)
| c when System.Char.IsDigit c -> digitsPrecision (i+1)
| _ -> i

let precision i =
if i >= len then failwithf "%s" <| FSComp.SR.forBadWidth()
match fmt.[i] with
| c when isDigit c -> info.precision <- true; false,digitsPrecision (i+1)
| c when System.Char.IsDigit c -> info.precision <- true; false,digitsPrecision (i+1)
| '*' -> info.precision <- true; true,(i+1)
| _ -> failwithf "%s" <| FSComp.SR.forPrecisionMissingAfterDot()

Expand All @@ -136,20 +134,20 @@ let parseFormatStringInternal (m:range) (g: TcGlobals) (context: FormatStringChe
let rec digitsWidthAndPrecision i =
if i >= len then failwithf "%s" <| FSComp.SR.forBadPrecision()
match fmt.[i] with
| c when isDigit c -> digitsWidthAndPrecision (i+1)
| c when System.Char.IsDigit c -> digitsWidthAndPrecision (i+1)
| _ -> optionalDotAndPrecision i

let widthAndPrecision i =
if i >= len then failwithf "%s" <| FSComp.SR.forBadPrecision()
match fmt.[i] with
| c when isDigit c -> false,digitsWidthAndPrecision i
| c when System.Char.IsDigit c -> false,digitsWidthAndPrecision i
| '*' -> true,optionalDotAndPrecision (i+1)
| _ -> false,optionalDotAndPrecision i

let rec digitsPosition n i =
if i >= len then failwithf "%s" <| FSComp.SR.forBadPrecision()
match fmt.[i] with
| c when isDigit c -> digitsPosition (n*10 + int c - int '0') (i+1)
| c when System.Char.IsDigit c -> digitsPosition (n*10 + int c - int '0') (i+1)
| '$' -> Some n, i+1
| _ -> None, i

Expand Down
10 changes: 4 additions & 6 deletions src/fsharp/FSharp.Core/printf.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ module internal PrintfImpl =
/// Set of helpers to parse format string
module private FormatString =

let inline isDigit c = c >= '0' && c <= '9'

let intFromString (s: string) pos =
let intFromString (s: string) pos =
let rec go acc i =
if isDigit s.[i] then
if Char.IsDigit s.[i] then
let n = int s.[i] - int '0'
go (acc * 10 + n) (i + 1)
else acc, i
Expand All @@ -125,13 +123,13 @@ module internal PrintfImpl =

let parseWidth (s: string) i =
if s.[i] = '*' then StarValue, (i + 1)
elif isDigit (s.[i]) then intFromString s i
elif Char.IsDigit s.[i] then intFromString s i
else NotSpecifiedValue, i

let parsePrecision (s: string) i =
if s.[i] = '.' then
if s.[i + 1] = '*' then StarValue, i + 2
elif isDigit (s.[i + 1]) then intFromString s (i + 1)
elif Char.IsDigit s.[i + 1] then intFromString s (i + 1)
else raise (ArgumentException("invalid precision value"))
else NotSpecifiedValue, i

Expand Down