< Summary

Line coverage
44%
Covered lines: 4
Uncovered lines: 5
Coverable lines: 9
Total lines: 137
Line coverage: 44.4%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Text.Json/src/System/Text/Json/JsonConstants.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace System.Text.Json
 5{
 6    internal static partial class JsonConstants
 7    {
 8        public const byte OpenBrace = (byte)'{';
 9        public const byte CloseBrace = (byte)'}';
 10        public const byte OpenBracket = (byte)'[';
 11        public const byte CloseBracket = (byte)']';
 12        public const byte Space = (byte)' ';
 13        public const byte CarriageReturn = (byte)'\r';
 14        public const byte LineFeed = (byte)'\n';
 15        public const byte Tab = (byte)'\t';
 16        public const byte ListSeparator = (byte)',';
 17        public const byte KeyValueSeparator = (byte)':';
 18        public const byte Quote = (byte)'"';
 19        public const byte BackSlash = (byte)'\\';
 20        public const byte Slash = (byte)'/';
 21        public const byte BackSpace = (byte)'\b';
 22        public const byte FormFeed = (byte)'\f';
 23        public const byte Asterisk = (byte)'*';
 24        public const byte Colon = (byte)':';
 25        public const byte Period = (byte)'.';
 26        public const byte Plus = (byte)'+';
 27        public const byte Hyphen = (byte)'-';
 28        public const byte UtcOffsetToken = (byte)'Z';
 29        public const byte TimePrefix = (byte)'T';
 30
 31        public const string NewLineLineFeed = "\n";
 32        public const string NewLineCarriageReturnLineFeed = "\r\n";
 33
 34        // \u2028 and \u2029 are considered respectively line and paragraph separators
 35        // UTF-8 representation for them is E2, 80, A8/A9
 36        public const byte StartingByteOfNonStandardSeparator = 0xE2;
 37
 12894538        public static ReadOnlySpan<byte> Utf8Bom => [0xEF, 0xBB, 0xBF];
 039        public static ReadOnlySpan<byte> TrueValue => "true"u8;
 25240        public static ReadOnlySpan<byte> FalseValue => "false"u8;
 041        public static ReadOnlySpan<byte> NullValue => "null"u8;
 42
 043        public static ReadOnlySpan<byte> NaNValue => "NaN"u8;
 444        public static ReadOnlySpan<byte> PositiveInfinityValue => "Infinity"u8;
 045        public static ReadOnlySpan<byte> NegativeInfinityValue => "-Infinity"u8;
 46        // The length of the longest of the three named literals above, i.e. "-Infinity".
 47        public const int MaximumFloatingPointConstantLength = 9;
 48
 49        // Used to search for the end of a number
 159650        public static ReadOnlySpan<byte> Delimiters => ",}] \n\r\t/"u8;
 51
 52        // Explicitly skipping ReverseSolidus since that is handled separately
 053        public static ReadOnlySpan<byte> EscapableChars => "\"nrt/ubf"u8;
 54
 55        public const int RemoveFlagsBitMask = 0x7FFFFFFF;
 56
 57        // In the worst case, an ASCII character represented as a single utf-8 byte could expand 6x when escaped.
 58        // For example: '+' becomes '\u002B'
 59        // Escaping surrogate pairs (represented by 3 or 4 utf-8 bytes) would expand to 12 bytes (which is still <= 6x).
 60        // The same factor applies to utf-16 characters.
 61        // This factor also serves as an upper bound for the combined escaping-and-transcoding pipeline.
 62        // A non-ASCII unicode character is either:
 63        // - escaped into an ASCII sequence (e.g. \uXXXX), so 1 UTF-16 char -> at most 6 UTF-8 bytes, or
 64        // - written directly as UTF-8 (e.g. when using a non-default encoder such as UnsafeRelaxedJsonEscaping),
 65        //   expanding at most 3x (MaxExpansionFactorWhileTranscoding), which is <= 6.
 66        public const int MaxExpansionFactorWhileEscaping = 6;
 67
 68        // In the worst case, a single UTF-16 character could be expanded to 3 UTF-8 bytes.
 69        // Only surrogate pairs expand to 4 UTF-8 bytes but that is a transformation of 2 UTF-16 characters going to 4 U
 70        // All other UTF-16 characters can be represented by either 1 or 2 UTF-8 bytes.
 71        public const int MaxExpansionFactorWhileTranscoding = 3;
 72
 73        // When transcoding from UTF8 -> UTF16, the byte count threshold where we rent from the array pool before perfor
 74        public const long ArrayPoolMaxSizeBeforeUsingNormalAlloc =
 75#if NET
 76            1024 * 1024 * 1024; // ArrayPool limit increased in .NET 6
 77#else
 78            1024 * 1024;
 79#endif
 80
 81        // The maximum number of characters allowed when writing raw UTF-16 JSON. This is the maximum length that we can
 82        // be safely transcoded to UTF-8 and fit within an integer-length span, given the max expansion factor of a sing
 83        public const int MaxUtf16RawValueLength = int.MaxValue / MaxExpansionFactorWhileTranscoding;
 84
 85        public const int MaxEscapedTokenSize = 1_000_000_000;   // Max size for already escaped value.
 86        public const int MaxUnescapedTokenSize = MaxEscapedTokenSize / MaxExpansionFactorWhileEscaping;  // 166_666_666 
 87        public const int MaxCharacterTokenSize = MaxEscapedTokenSize / MaxExpansionFactorWhileEscaping; // 166_666_666 c
 88
 89        public const int MaximumFormatBooleanLength = 5;
 90        public const int MaximumFormatInt64Length = 20;   // 19 + sign (i.e. -9223372036854775808)
 91        public const int MaximumFormatUInt32Length = 10;  // i.e. 4294967295
 92        public const int MaximumFormatUInt64Length = 20;  // i.e. 18446744073709551615
 93        public const int MaximumFormatDoubleLength = 128;  // default (i.e. 'G'), using 128 (rather than say 32) to be f
 94        public const int MaximumFormatSingleLength = 128;  // default (i.e. 'G'), using 128 (rather than say 32) to be f
 95        public const int MaximumFormatDecimalLength = 31; // default (i.e. 'G')
 96        public const int MaximumFormatGuidLength = 36;    // default (i.e. 'D'), 8 + 4 + 4 + 4 + 12 + 4 for the hyphens 
 97        public const int MaximumEscapedGuidLength = MaxExpansionFactorWhileEscaping * MaximumFormatGuidLength;
 98        public const int MaximumFormatDateTimeLength = 27;    // StandardFormat 'O', e.g. 2017-06-12T05:30:45.7680000
 99        public const int MaximumFormatDateTimeOffsetLength = 33;  // StandardFormat 'O', e.g. 2017-06-12T05:30:45.768000
 100        public const int MaxDateTimeUtcOffsetHours = 14; // The UTC offset portion of a TimeSpan or DateTime can be no m
 101        public const int DateTimeNumFractionDigits = 7;  // TimeSpan and DateTime formats allow exactly up to many digit
 102        public const int MaxDateTimeFraction = 9_999_999;  // The largest fraction expressible by TimeSpan and DateTime 
 103        public const int DateTimeParseNumFractionDigits = 16; // The maximum number of fraction digits the Json DateTime
 104        public const int MaximumDateTimeOffsetParseLength = (MaximumFormatDateTimeOffsetLength +
 105            (DateTimeParseNumFractionDigits - DateTimeNumFractionDigits)); // Like StandardFormat 'O' for DateTimeOffset
 106        public const int MinimumDateTimeParseLength = 10; // YYYY-MM-DD
 107        public const int MaximumEscapedDateTimeOffsetParseLength = MaxExpansionFactorWhileEscaping * MaximumDateTimeOffs
 108
 109        public const int MaximumLiteralLength = 5; // Must be able to fit null, true, & false.
 110
 111        // Encoding Helpers
 112        public const char HighSurrogateStart = '\ud800';
 113        public const char HighSurrogateEnd = '\udbff';
 114        public const char LowSurrogateStart = '\udc00';
 115        public const char LowSurrogateEnd = '\udfff';
 116
 117        public const int UnicodePlane01StartValue = 0x10000;
 118        public const int HighSurrogateStartValue = 0xD800;
 119        public const int HighSurrogateEndValue = 0xDBFF;
 120        public const int LowSurrogateStartValue = 0xDC00;
 121        public const int LowSurrogateEndValue = 0xDFFF;
 122        public const int BitShiftBy10 = 0x400;
 123
 124        // The maximum number of parameters a constructor can have where it can be considered
 125        // for a path on deserialization where we don't box the constructor arguments.
 126        public const int UnboxedParameterCountThreshold = 4;
 127
 128        // Two space characters is the default indentation.
 129        public const char DefaultIndentCharacter = ' ';
 130        public const char TabIndentCharacter = '\t';
 131        public const int DefaultIndentSize = 2;
 132        public const int MinimumIndentSize = 0;
 133        public const int MaximumIndentSize = 127; // If this value is changed, the impact on the options masking used in
 134
 135    }
 136}
 137