Skip to content

Commit 86a584d

Browse files
forkiKevinRansom
authored andcommitted
Use Char.isDigit from .NET (#6524)
* Use Char.isDigit from .NET * Use Char.isDigit from .NET
1 parent 44d9852 commit 86a584d

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/fsharp/CheckFormatStrings.fs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ let mkFlexibleDecimalFormatTypar (g: TcGlobals) m =
3434
let mkFlexibleFloatFormatTypar (g: TcGlobals) m =
3535
mkFlexibleFormatTypar m [ g.float_ty; g.float32_ty; g.decimal_ty ] g.float_ty
3636

37-
let isDigit c = ('0' <= c && c <= '9')
38-
3937
type FormatInfoRegister =
4038
{ mutable leftJustify : bool
4139
mutable numPrefixIfPos : char option
@@ -117,13 +115,13 @@ let parseFormatStringInternal (m:range) (g: TcGlobals) (context: FormatStringChe
117115
let rec digitsPrecision i =
118116
if i >= len then failwithf "%s" <| FSComp.SR.forBadPrecision()
119117
match fmt.[i] with
120-
| c when isDigit c -> digitsPrecision (i+1)
118+
| c when System.Char.IsDigit c -> digitsPrecision (i+1)
121119
| _ -> i
122120

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

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

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

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

src/fsharp/FSharp.Core/printf.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ module internal PrintfImpl =
103103
/// Set of helpers to parse format string
104104
module private FormatString =
105105

106-
let inline isDigit c = c >= '0' && c <= '9'
107-
108-
let intFromString (s: string) pos =
106+
let intFromString (s: string) pos =
109107
let rec go acc i =
110-
if isDigit s.[i] then
108+
if Char.IsDigit s.[i] then
111109
let n = int s.[i] - int '0'
112110
go (acc * 10 + n) (i + 1)
113111
else acc, i
@@ -125,13 +123,13 @@ module internal PrintfImpl =
125123

126124
let parseWidth (s: string) i =
127125
if s.[i] = '*' then StarValue, (i + 1)
128-
elif isDigit (s.[i]) then intFromString s i
126+
elif Char.IsDigit s.[i] then intFromString s i
129127
else NotSpecifiedValue, i
130128

131129
let parsePrecision (s: string) i =
132130
if s.[i] = '.' then
133131
if s.[i + 1] = '*' then StarValue, i + 2
134-
elif isDigit (s.[i + 1]) then intFromString s (i + 1)
132+
elif Char.IsDigit s.[i + 1] then intFromString s (i + 1)
135133
else raise (ArgumentException("invalid precision value"))
136134
else NotSpecifiedValue, i
137135

0 commit comments

Comments
 (0)