Skip to content

Commit a27a91f

Browse files
Change ParseRealLiteral to remove literals before parsing
1 parent e8dd351 commit a27a91f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/System.Linq.Dynamic.Core/Parser/NumberParser.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Globalization;
1+
using System.Globalization;
22
using System.Linq.Dynamic.Core.Exceptions;
33
using System.Linq.Dynamic.Core.Validation;
44
using System.Linq.Expressions;
@@ -161,19 +161,34 @@ public Expression ParseIntegerLiteral(int tokenPosition, string text)
161161
/// </summary>
162162
public Expression ParseRealLiteral(string text, char qualifier, bool stripQualifier)
163163
{
164+
if (stripQualifier)
165+
{
166+
var pos = text.Length - 1;
167+
while (pos >= 0 && Qualifiers.Contains(text[pos]))
168+
{
169+
pos--;
170+
}
171+
172+
if (pos < text.Length - 1)
173+
{
174+
qualifier = text[pos + 1];
175+
text = text.Substring(0, pos + 1);
176+
}
177+
}
178+
164179
switch (qualifier)
165180
{
166181
case 'f':
167182
case 'F':
168-
return _constantExpressionHelper.CreateLiteral(ParseNumber(stripQualifier ? text.Substring(0, text.Length - 1) : text, typeof(float))!, text);
183+
return ConstantExpressionHelper.CreateLiteral(ParseNumber(text, typeof(float))!, text);
169184

170185
case 'm':
171186
case 'M':
172-
return _constantExpressionHelper.CreateLiteral(ParseNumber(stripQualifier ? text.Substring(0, text.Length - 1) : text, typeof(decimal))!, text);
187+
return ConstantExpressionHelper.CreateLiteral(ParseNumber(text, typeof(decimal))!, text);
173188

174189
case 'd':
175190
case 'D':
176-
return _constantExpressionHelper.CreateLiteral(ParseNumber(stripQualifier ? text.Substring(0, text.Length - 1) : text, typeof(double))!, text);
191+
return ConstantExpressionHelper.CreateLiteral(ParseNumber(text, typeof(double))!, text);
177192

178193
default:
179194
return _constantExpressionHelper.CreateLiteral(ParseNumber(text, typeof(double))!, text);
@@ -298,4 +313,4 @@ private Expression ParseAsBinary(int tokenPosition, string text, bool isNegative
298313
throw new ParseException(string.Format(_culture, Res.InvalidBinaryIntegerLiteral, text), tokenPosition);
299314
}
300315
}
301-
}
316+
}

0 commit comments

Comments
 (0)