internal bool IsUnknownSize => _sizeOrLengthUnion == UnknownSize;
/// <summary>
- /// Number: Use scientific format.
/// String/PropertyName: Unescaping is required.
/// Array: At least one element is an object/array.
/// Otherwise; false
ReadOnlySpan<byte> data = _utf8Json.Span;
ReadOnlySpan<byte> segment = data.Slice(row.Location, row.SizeOrLength);
- char standardFormat = row.HasComplexChildren ? JsonConstants.ScientificNotationFormat : default;
-
- if (Utf8Parser.TryParse(segment, out double tmp, out int bytesConsumed, standardFormat) &&
+ if (Utf8Parser.TryParse(segment, out double tmp, out int bytesConsumed) &&
segment.Length == bytesConsumed)
{
value = tmp;
ReadOnlySpan<byte> data = _utf8Json.Span;
ReadOnlySpan<byte> segment = data.Slice(row.Location, row.SizeOrLength);
- char standardFormat = row.HasComplexChildren ? JsonConstants.ScientificNotationFormat : default;
-
- if (Utf8Parser.TryParse(segment, out float tmp, out int bytesConsumed, standardFormat) &&
+ if (Utf8Parser.TryParse(segment, out float tmp, out int bytesConsumed) &&
segment.Length == bytesConsumed)
{
value = tmp;
ReadOnlySpan<byte> data = _utf8Json.Span;
ReadOnlySpan<byte> segment = data.Slice(row.Location, row.SizeOrLength);
- char standardFormat = row.HasComplexChildren ? JsonConstants.ScientificNotationFormat : default;
-
- if (Utf8Parser.TryParse(segment, out decimal tmp, out int bytesConsumed, standardFormat) &&
+ if (Utf8Parser.TryParse(segment, out decimal tmp, out int bytesConsumed) &&
segment.Length == bytesConsumed)
{
value = tmp;
else
{
database.Append(tokenType, tokenStart, reader.ValueSpan.Length);
-
- if (tokenType == JsonTokenType.Number)
- {
- switch (reader._numberFormat)
- {
- case JsonConstants.ScientificNotationFormat:
- database.SetHasComplexChildren(database.Length - DbRow.Size);
- break;
- default:
- Debug.Assert(
- reader._numberFormat == default,
- $"Unhandled numeric format {reader._numberFormat}");
- break;
- }
- }
}
}
public const int MinimumDateTimeParseLength = 10; // YYYY-MM-DD
public const int MaximumEscapedDateTimeOffsetParseLength = MaxExpansionFactorWhileEscaping * MaximumDateTimeOffsetParseLength;
- internal const char ScientificNotationFormat = 'e';
-
// Encoding Helpers
public const char HighSurrogateStart = '\ud800';
public const char HighSurrogateEnd = '\udbff';
return false;
}
- public static char GetFloatingPointStandardParseFormat(ReadOnlySpan<byte> span)
- {
- // Assume that 'e/E' is closer to the end.
- int startIndex = span.Length - 1;
- for (int i = startIndex; i >= 0; i--)
- {
- byte token = span[i];
- if (token == 'E' || token == 'e')
- {
- return JsonConstants.ScientificNotationFormat;
- }
- }
- return default;
- }
-
public static bool TryGetFloatingPointConstant(ReadOnlySpan<byte> span, out float value)
{
if (span.Length == 3)
internal long _bytePositionInLine;
internal bool _inObject;
internal bool _isNotPrimitive;
- internal char _numberFormat;
internal bool _stringHasEscaping;
internal bool _trailingCommaBeforeComment;
internal JsonTokenType _tokenType;
_bytePositionInLine = default;
_inObject = default;
_isNotPrimitive = default;
- _numberFormat = default;
_stringHasEscaping = default;
_trailingCommaBeforeComment = default;
_tokenType = default;
_bytePositionInLine = state._bytePositionInLine;
_inObject = state._inObject;
_isNotPrimitive = state._isNotPrimitive;
- _numberFormat = state._numberFormat;
_stringHasEscaping = state._stringHasEscaping;
_trailingCommaBeforeComment = state._trailingCommaBeforeComment;
_tokenType = state._tokenType;
// TODO: https://github.com/dotnet/runtime/issues/27837
Debug.Assert(data.Length > 0);
- _numberFormat = default;
-
PartialStateForRollback rollBackState = CaptureState();
consumed = 0;
Debug.Assert(nextByte == 'E' || nextByte == 'e');
i++;
- _numberFormat = JsonConstants.ScientificNotationFormat;
_bytePositionInLine++;
signResult = ConsumeSignMultiSegment(ref data, ref i, rollBackState);
return value;
}
- char numberFormat = JsonReaderHelper.GetFloatingPointStandardParseFormat(span);
- if (Utf8Parser.TryParse(span, out value, out int bytesConsumed, numberFormat)
+ if (Utf8Parser.TryParse(span, out value, out int bytesConsumed)
&& span.Length == bytesConsumed)
{
// NETCOREAPP implementation of the TryParse method above permits case-insenstive variants of the
return value;
}
- char numberFormat = JsonReaderHelper.GetFloatingPointStandardParseFormat(span);
- if (Utf8Parser.TryParse(span, out value, out int bytesConsumed, numberFormat)
+ if (Utf8Parser.TryParse(span, out value, out int bytesConsumed)
&& span.Length == bytesConsumed)
{
- // NETCOREAPP implmentation of the TryParse method above permits case-insenstive variants of the
+ // NETCOREAPP implementation of the TryParse method above permits case-insenstive variants of the
// float constants "NaN", "Infinity", "-Infinity". This differs from the NETFRAMEWORK implementation.
// The following logic reconciles the two implementations to enforce consistent behavior.
if (!double.IsNaN(value) && !double.IsPositiveInfinity(value) && !double.IsNegativeInfinity(value))
internal decimal GetDecimalWithQuotes()
{
ReadOnlySpan<byte> span = GetUnescapedSpan();
-
- char numberFormat = JsonReaderHelper.GetFloatingPointStandardParseFormat(span);
- if (Utf8Parser.TryParse(span, out decimal value, out int bytesConsumed, numberFormat)
- && span.Length == bytesConsumed)
+ if (!TryGetDecimalCore(out decimal value, span))
{
- return value;
+ throw ThrowHelper.GetFormatException(NumericType.Decimal);
}
-
- throw ThrowHelper.GetFormatException(NumericType.Decimal);
+ return value;
}
/// <summary>
ReadOnlySpan<byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan;
- if (Utf8Parser.TryParse(span, out float tmp, out int bytesConsumed, _numberFormat)
+ if (Utf8Parser.TryParse(span, out float tmp, out int bytesConsumed)
&& span.Length == bytesConsumed)
{
value = tmp;
ReadOnlySpan<byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan;
- if (Utf8Parser.TryParse(span, out double tmp, out int bytesConsumed, _numberFormat)
+ if (Utf8Parser.TryParse(span, out double tmp, out int bytesConsumed)
&& span.Length == bytesConsumed)
{
value = tmp;
}
ReadOnlySpan<byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan;
+ return TryGetDecimalCore(out value, span);
+ }
- if (Utf8Parser.TryParse(span, out decimal tmp, out int bytesConsumed, _numberFormat)
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal bool TryGetDecimalCore(out decimal value, ReadOnlySpan<byte> span)
+ {
+ if (Utf8Parser.TryParse(span, out decimal tmp, out int bytesConsumed)
&& span.Length == bytesConsumed)
{
value = tmp;
private int _consumed;
private bool _inObject;
private bool _isNotPrimitive;
- internal char _numberFormat;
private JsonTokenType _tokenType;
private JsonTokenType _previousTokenType;
private JsonReaderOptions _readerOptions;
_bytePositionInLine = _bytePositionInLine,
_inObject = _inObject,
_isNotPrimitive = _isNotPrimitive,
- _numberFormat = _numberFormat,
_stringHasEscaping = _stringHasEscaping,
_trailingCommaBeforeComment = _trailingCommaBeforeComment,
_tokenType = _tokenType,
_bytePositionInLine = state._bytePositionInLine;
_inObject = state._inObject;
_isNotPrimitive = state._isNotPrimitive;
- _numberFormat = state._numberFormat;
_stringHasEscaping = state._stringHasEscaping;
_trailingCommaBeforeComment = state._trailingCommaBeforeComment;
_tokenType = state._tokenType;
// TODO: https://github.com/dotnet/runtime/issues/27837
Debug.Assert(data.Length > 0);
- _numberFormat = default;
consumed = 0;
int i = 0;
Debug.Assert(nextByte == 'E' || nextByte == 'e');
i++;
- _numberFormat = JsonConstants.ScientificNotationFormat;
signResult = ConsumeSign(ref data, ref i);
if (signResult == ConsumeNumberResult.NeedMoreData)