diff --git a/src/fsharp/CheckFormatStrings.fs b/src/fsharp/CheckFormatStrings.fs index 024a2e7d13c..1622a61351c 100644 --- a/src/fsharp/CheckFormatStrings.fs +++ b/src/fsharp/CheckFormatStrings.fs @@ -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 @@ -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() @@ -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 diff --git a/src/fsharp/FSharp.Core/printf.fs b/src/fsharp/FSharp.Core/printf.fs index eb0996da06d..1c19f11cb3b 100644 --- a/src/fsharp/FSharp.Core/printf.fs +++ b/src/fsharp/FSharp.Core/printf.fs @@ -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 @@ -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