| | | 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 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Runtime.CompilerServices; |
| | | 6 | | using System.Text; |
| | | 7 | | |
| | | 8 | | namespace System.Globalization |
| | | 9 | | { |
| | | 10 | | /// <remarks> |
| | | 11 | | /// Property Default Description |
| | | 12 | | /// PositiveSign '+' Character used to indicate positive values. |
| | | 13 | | /// NegativeSign '-' Character used to indicate negative values. |
| | | 14 | | /// NumberDecimalSeparator '.' The character used as the decimal separator. |
| | | 15 | | /// NumberGroupSeparator ',' The character used to separate groups of |
| | | 16 | | /// digits to the left of the decimal point. |
| | | 17 | | /// NumberDecimalDigits 2 The default number of decimal places. |
| | | 18 | | /// NumberGroupSizes 3 The number of digits in each group to the |
| | | 19 | | /// left of the decimal point. |
| | | 20 | | /// NaNSymbol "NaN" The string used to represent NaN values. |
| | | 21 | | /// PositiveInfinitySymbol"Infinity" The string used to represent positive |
| | | 22 | | /// infinities. |
| | | 23 | | /// NegativeInfinitySymbol"-Infinity" The string used to represent negative |
| | | 24 | | /// infinities. |
| | | 25 | | /// |
| | | 26 | | /// Property Default Description |
| | | 27 | | /// CurrencyDecimalSeparator '.' The character used as the decimal |
| | | 28 | | /// separator. |
| | | 29 | | /// CurrencyGroupSeparator ',' The character used to separate groups |
| | | 30 | | /// of digits to the left of the decimal |
| | | 31 | | /// point. |
| | | 32 | | /// CurrencyDecimalDigits 2 The default number of decimal places. |
| | | 33 | | /// CurrencyGroupSizes 3 The number of digits in each group to |
| | | 34 | | /// the left of the decimal point. |
| | | 35 | | /// CurrencyPositivePattern 0 The format of positive values. |
| | | 36 | | /// CurrencyNegativePattern 0 The format of negative values. |
| | | 37 | | /// CurrencySymbol "$" String used as local monetary symbol. |
| | | 38 | | /// </remarks> |
| | | 39 | | public sealed class NumberFormatInfo : IFormatProvider, ICloneable |
| | | 40 | | { |
| | 0 | 41 | | internal static readonly string[] s_asciiDigits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; |
| | 0 | 42 | | internal static readonly int[] s_intArrayWithElement3 = [3]; |
| | | 43 | | |
| | 0 | 44 | | internal int[] _numberGroupSizes = s_intArrayWithElement3; // default to [3]; only clones of this array are hand |
| | 0 | 45 | | internal int[] _currencyGroupSizes = s_intArrayWithElement3; // default to [3]; only clones of this array are ha |
| | 0 | 46 | | internal int[] _percentGroupSizes = s_intArrayWithElement3; // default to [3]; only clones of this array are han |
| | 0 | 47 | | internal string _positiveSign = "+"; |
| | 0 | 48 | | internal string _negativeSign = "-"; |
| | 0 | 49 | | internal string _numberDecimalSeparator = "."; |
| | 0 | 50 | | internal string _numberGroupSeparator = ","; |
| | 0 | 51 | | internal string _currencyGroupSeparator = ","; |
| | 0 | 52 | | internal string _currencyDecimalSeparator = "."; |
| | 0 | 53 | | internal string _currencySymbol = "\x00a4"; // U+00a4 is the symbol for International Monetary Fund. |
| | 0 | 54 | | internal string _nanSymbol = "NaN"; |
| | 0 | 55 | | internal string _positiveInfinitySymbol = "Infinity"; |
| | 0 | 56 | | internal string _negativeInfinitySymbol = "-Infinity"; |
| | 0 | 57 | | internal string _percentDecimalSeparator = "."; |
| | 0 | 58 | | internal string _percentGroupSeparator = ","; |
| | 0 | 59 | | internal string _percentSymbol = "%"; |
| | 0 | 60 | | internal string _perMilleSymbol = "\u2030"; |
| | | 61 | | |
| | | 62 | | internal byte[]? _positiveSignUtf8; |
| | | 63 | | internal byte[]? _negativeSignUtf8; |
| | | 64 | | internal byte[]? _currencySymbolUtf8; |
| | | 65 | | internal byte[]? _numberDecimalSeparatorUtf8; |
| | | 66 | | internal byte[]? _currencyDecimalSeparatorUtf8; |
| | | 67 | | internal byte[]? _currencyGroupSeparatorUtf8; |
| | | 68 | | internal byte[]? _numberGroupSeparatorUtf8; |
| | | 69 | | internal byte[]? _percentSymbolUtf8; |
| | | 70 | | internal byte[]? _percentDecimalSeparatorUtf8; |
| | | 71 | | internal byte[]? _percentGroupSeparatorUtf8; |
| | | 72 | | internal byte[]? _perMilleSymbolUtf8; |
| | | 73 | | internal byte[]? _nanSymbolUtf8; |
| | | 74 | | internal byte[]? _positiveInfinitySymbolUtf8; |
| | | 75 | | internal byte[]? _negativeInfinitySymbolUtf8; |
| | | 76 | | |
| | 0 | 77 | | internal string[] _nativeDigits = s_asciiDigits; // default to ASCII digits; only clones of this array are hande |
| | | 78 | | |
| | 0 | 79 | | internal int _numberDecimalDigits = 2; |
| | 0 | 80 | | internal int _currencyDecimalDigits = 2; |
| | | 81 | | internal int _currencyPositivePattern; |
| | | 82 | | internal int _currencyNegativePattern; |
| | 0 | 83 | | internal int _numberNegativePattern = 1; |
| | | 84 | | internal int _percentPositivePattern; |
| | | 85 | | internal int _percentNegativePattern; |
| | 0 | 86 | | internal int _percentDecimalDigits = 2; |
| | | 87 | | |
| | 0 | 88 | | internal int _digitSubstitution = (int)DigitShapes.None; |
| | | 89 | | |
| | | 90 | | internal bool _isReadOnly; |
| | | 91 | | |
| | 0 | 92 | | private bool _hasInvariantNumberSigns = true; |
| | | 93 | | |
| | | 94 | | // When _allowHyphenDuringParsing is set to true, we'll allow the number parser to accept the hyphen `-` U+002D |
| | | 95 | | // negative sign is not the hyphen. For example, the Swedish culture (e.g. "sv-SE") has U+2212 as the negative s |
| | | 96 | | private bool _allowHyphenDuringParsing; |
| | | 97 | | |
| | | 98 | | // Each UTF-8 cache is allocated one byte longer than the text it holds and the returned span |
| | | 99 | | // excludes that trailing NUL. Consumers should still bound themselves by the span length; the |
| | | 100 | | // terminator only exists so that a helper which scans for one cannot run off the end. |
| | | 101 | | private static ReadOnlySpan<byte> GetUtf8Span(ref byte[]? utf8Cache, string value) |
| | | 102 | | { |
| | 0 | 103 | | byte[] utf8 = utf8Cache ?? CreateUtf8Cache(ref utf8Cache, value); |
| | 0 | 104 | | Debug.Assert(utf8.Length > 0); |
| | 0 | 105 | | return utf8.AsSpan(0, utf8.Length - 1); |
| | | 106 | | } |
| | | 107 | | |
| | | 108 | | [MethodImpl(MethodImplOptions.NoInlining)] |
| | | 109 | | private static byte[] CreateUtf8Cache(ref byte[]? utf8Cache, string value) |
| | | 110 | | { |
| | 0 | 111 | | byte[] utf8 = new byte[Encoding.UTF8.GetByteCount(value) + 1]; |
| | 0 | 112 | | Encoding.UTF8.GetBytes(value, utf8); |
| | 0 | 113 | | return utf8Cache = utf8; |
| | | 114 | | } |
| | | 115 | | |
| | 0 | 116 | | public NumberFormatInfo() |
| | | 117 | | { |
| | 0 | 118 | | } |
| | | 119 | | |
| | | 120 | | private static void VerifyNativeDigits(string[] nativeDig, string propertyName) |
| | | 121 | | { |
| | 0 | 122 | | ArgumentNullException.ThrowIfNull(nativeDig); |
| | | 123 | | |
| | 0 | 124 | | if (nativeDig.Length != 10) |
| | | 125 | | { |
| | 0 | 126 | | throw new ArgumentException(SR.Argument_InvalidNativeDigitCount, propertyName); |
| | | 127 | | } |
| | | 128 | | |
| | 0 | 129 | | for (int i = 0; i < nativeDig.Length; i++) |
| | | 130 | | { |
| | 0 | 131 | | if (nativeDig[i] == null) |
| | | 132 | | { |
| | 0 | 133 | | throw new ArgumentNullException(propertyName, SR.ArgumentNull_ArrayValue); |
| | | 134 | | } |
| | | 135 | | |
| | 0 | 136 | | if (nativeDig[i].Length != 1) |
| | | 137 | | { |
| | 0 | 138 | | if (nativeDig[i].Length != 2) |
| | | 139 | | { |
| | | 140 | | // Not 1 or 2 UTF-16 code points |
| | 0 | 141 | | throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName); |
| | | 142 | | } |
| | 0 | 143 | | else if (!char.IsSurrogatePair(nativeDig[i][0], nativeDig[i][1])) |
| | | 144 | | { |
| | | 145 | | // 2 UTF-6 code points, but not a surrogate pair |
| | 0 | 146 | | throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName); |
| | | 147 | | } |
| | | 148 | | } |
| | | 149 | | |
| | 0 | 150 | | if (CharUnicodeInfo.GetDecimalDigitValue(nativeDig[i], 0) != i && |
| | 0 | 151 | | CharUnicodeInfo.GetUnicodeCategory(nativeDig[i], 0) != UnicodeCategory.PrivateUse) |
| | | 152 | | { |
| | | 153 | | // Not the appropriate digit according to the Unicode data properties |
| | | 154 | | // (Digit 0 must be a 0, etc.). |
| | 0 | 155 | | throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName); |
| | | 156 | | } |
| | | 157 | | } |
| | 0 | 158 | | } |
| | | 159 | | |
| | | 160 | | private static void VerifyDigitSubstitution(DigitShapes digitSub, string propertyName) |
| | | 161 | | { |
| | | 162 | | switch (digitSub) |
| | | 163 | | { |
| | | 164 | | case DigitShapes.Context: |
| | | 165 | | case DigitShapes.None: |
| | | 166 | | case DigitShapes.NativeNational: |
| | | 167 | | // Success. |
| | | 168 | | break; |
| | | 169 | | |
| | | 170 | | default: |
| | 0 | 171 | | throw new ArgumentException(SR.Argument_InvalidDigitSubstitution, propertyName); |
| | | 172 | | } |
| | 0 | 173 | | } |
| | | 174 | | |
| | 0 | 175 | | internal bool HasInvariantNumberSigns => _hasInvariantNumberSigns; |
| | 0 | 176 | | internal bool AllowHyphenDuringParsing() => _allowHyphenDuringParsing; |
| | | 177 | | |
| | | 178 | | private void InitializeInvariantAndNegativeSignFlags() |
| | | 179 | | { |
| | 0 | 180 | | _hasInvariantNumberSigns = _positiveSign == "+" && _negativeSign == "-"; |
| | | 181 | | |
| | | 182 | | // The list of the Minus characters are picked up from the CLDR parse lenient data. |
| | | 183 | | // e.g. https://github.com/unicode-org/cldr/blob/feb602b06bd18ba7333464bd648b68292e8aa54d/common/main/sw.xml |
| | | 184 | | |
| | 0 | 185 | | _allowHyphenDuringParsing = _negativeSign.Length == 1 && |
| | 0 | 186 | | _negativeSign[0] switch { |
| | 0 | 187 | | '\u2012' or // Figure Dash |
| | 0 | 188 | | '\u207B' or // Superscript Minus |
| | 0 | 189 | | '\u208B' or // Subscript Minus |
| | 0 | 190 | | '\u2212' or // Minus Sign |
| | 0 | 191 | | '\u2796' or // Heavy Minus Sign |
| | 0 | 192 | | '\uFE63' or // Small Hyphen-Minus |
| | 0 | 193 | | '\uFF0D' => true, // Fullwidth Hyphen-Minus |
| | 0 | 194 | | _ => false |
| | 0 | 195 | | }; |
| | 0 | 196 | | } |
| | | 197 | | |
| | 0 | 198 | | internal NumberFormatInfo(CultureData? cultureData) |
| | | 199 | | { |
| | 0 | 200 | | if (cultureData != null) |
| | | 201 | | { |
| | | 202 | | // We directly use fields here since these data is coming from data table or Win32, so we |
| | | 203 | | // don't need to verify their values (except for invalid parsing situations). |
| | 0 | 204 | | cultureData.GetNFIValues(this); |
| | | 205 | | |
| | 0 | 206 | | InitializeInvariantAndNegativeSignFlags(); |
| | | 207 | | } |
| | 0 | 208 | | } |
| | | 209 | | |
| | | 210 | | private void VerifyWritable() |
| | | 211 | | { |
| | 0 | 212 | | if (_isReadOnly) |
| | | 213 | | { |
| | 0 | 214 | | throw new InvalidOperationException(SR.InvalidOperation_ReadOnly); |
| | | 215 | | } |
| | 0 | 216 | | } |
| | | 217 | | |
| | | 218 | | /// <summary> |
| | | 219 | | /// Returns a default NumberFormatInfo that will be universally |
| | | 220 | | /// supported and constant irrespective of the current culture. |
| | | 221 | | /// Used by FromString methods. |
| | | 222 | | /// </summary> |
| | 0 | 223 | | public static NumberFormatInfo InvariantInfo => field ??= |
| | 0 | 224 | | // Lazy create the invariant info. This cannot be done in a .cctor because exceptions can |
| | 0 | 225 | | // be thrown out of a .cctor stack that will need this. |
| | 0 | 226 | | CultureInfo.InvariantCulture.NumberFormat; |
| | | 227 | | |
| | | 228 | | public static NumberFormatInfo GetInstance(IFormatProvider? formatProvider) |
| | | 229 | | { |
| | 0 | 230 | | return formatProvider == null ? |
| | 0 | 231 | | CurrentInfo : // Fast path for a null provider |
| | 0 | 232 | | GetProviderNonNull(formatProvider); |
| | | 233 | | |
| | | 234 | | static NumberFormatInfo GetProviderNonNull(IFormatProvider provider) |
| | | 235 | | { |
| | | 236 | | // Fast path for a regular CultureInfo |
| | 0 | 237 | | if (provider.GetType() == typeof(CultureInfo) && ((CultureInfo)provider)._numInfo is { } info) |
| | | 238 | | { |
| | 0 | 239 | | return info; |
| | | 240 | | } |
| | | 241 | | |
| | 0 | 242 | | return |
| | 0 | 243 | | provider as NumberFormatInfo ?? // Fast path for an NFI |
| | 0 | 244 | | provider.GetFormat(typeof(NumberFormatInfo)) as NumberFormatInfo ?? |
| | 0 | 245 | | CurrentInfo; |
| | | 246 | | } |
| | | 247 | | } |
| | | 248 | | |
| | | 249 | | public object Clone() |
| | | 250 | | { |
| | 0 | 251 | | NumberFormatInfo n = (NumberFormatInfo)MemberwiseClone(); |
| | 0 | 252 | | n._isReadOnly = false; |
| | 0 | 253 | | return n; |
| | | 254 | | } |
| | | 255 | | |
| | | 256 | | public int CurrencyDecimalDigits |
| | | 257 | | { |
| | 0 | 258 | | get => _currencyDecimalDigits; |
| | | 259 | | set |
| | | 260 | | { |
| | 0 | 261 | | if (value < 0 || value > 99) |
| | | 262 | | { |
| | 0 | 263 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 99); |
| | | 264 | | } |
| | | 265 | | |
| | 0 | 266 | | VerifyWritable(); |
| | 0 | 267 | | _currencyDecimalDigits = value; |
| | 0 | 268 | | } |
| | | 269 | | } |
| | | 270 | | |
| | | 271 | | public string CurrencyDecimalSeparator |
| | | 272 | | { |
| | 0 | 273 | | get => _currencyDecimalSeparator; |
| | | 274 | | set |
| | | 275 | | { |
| | 0 | 276 | | VerifyWritable(); |
| | 0 | 277 | | ArgumentException.ThrowIfNullOrEmpty(value); |
| | 0 | 278 | | _currencyDecimalSeparator = value; |
| | 0 | 279 | | _currencyDecimalSeparatorUtf8 = null; |
| | 0 | 280 | | } |
| | | 281 | | } |
| | | 282 | | |
| | | 283 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 284 | | internal ReadOnlySpan<TChar> CurrencyDecimalSeparatorTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 285 | | { |
| | 0 | 286 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 287 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 288 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_currencyDecimalSeparator) : |
| | 0 | 289 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _currencyDecimalSeparatorUtf8, _ |
| | | 290 | | } |
| | | 291 | | |
| | 0 | 292 | | public bool IsReadOnly => _isReadOnly; |
| | | 293 | | |
| | | 294 | | /// <summary> |
| | | 295 | | /// Check the values of the groupSize array. |
| | | 296 | | /// Every element in the groupSize array should be between 1 and 9 |
| | | 297 | | /// except the last element could be zero. |
| | | 298 | | /// </summary> |
| | | 299 | | internal static void CheckGroupSize(string propName, int[] groupSize) |
| | | 300 | | { |
| | 0 | 301 | | for (int i = 0; i < groupSize.Length; i++) |
| | | 302 | | { |
| | 0 | 303 | | if (groupSize[i] < 1) |
| | | 304 | | { |
| | 0 | 305 | | if (i == groupSize.Length - 1 && groupSize[i] == 0) |
| | | 306 | | { |
| | 0 | 307 | | return; |
| | | 308 | | } |
| | | 309 | | |
| | 0 | 310 | | throw new ArgumentException(SR.Argument_InvalidGroupSize, propName); |
| | | 311 | | } |
| | 0 | 312 | | else if (groupSize[i] > 9) |
| | | 313 | | { |
| | 0 | 314 | | throw new ArgumentException(SR.Argument_InvalidGroupSize, propName); |
| | | 315 | | } |
| | | 316 | | } |
| | 0 | 317 | | } |
| | | 318 | | |
| | | 319 | | public int[] CurrencyGroupSizes |
| | | 320 | | { |
| | 0 | 321 | | get => (int[])_currencyGroupSizes.Clone(); |
| | | 322 | | set |
| | | 323 | | { |
| | 0 | 324 | | ArgumentNullException.ThrowIfNull(value); |
| | | 325 | | |
| | 0 | 326 | | VerifyWritable(); |
| | | 327 | | |
| | 0 | 328 | | int[] inputSizes = (int[])value.Clone(); |
| | 0 | 329 | | CheckGroupSize(nameof(value), inputSizes); |
| | 0 | 330 | | _currencyGroupSizes = inputSizes; |
| | 0 | 331 | | } |
| | | 332 | | } |
| | | 333 | | |
| | | 334 | | public int[] NumberGroupSizes |
| | | 335 | | { |
| | 0 | 336 | | get => (int[])_numberGroupSizes.Clone(); |
| | | 337 | | set |
| | | 338 | | { |
| | 0 | 339 | | ArgumentNullException.ThrowIfNull(value); |
| | | 340 | | |
| | 0 | 341 | | VerifyWritable(); |
| | | 342 | | |
| | 0 | 343 | | int[] inputSizes = (int[])value.Clone(); |
| | 0 | 344 | | CheckGroupSize(nameof(value), inputSizes); |
| | 0 | 345 | | _numberGroupSizes = inputSizes; |
| | 0 | 346 | | } |
| | | 347 | | } |
| | | 348 | | |
| | | 349 | | public int[] PercentGroupSizes |
| | | 350 | | { |
| | 0 | 351 | | get => (int[])_percentGroupSizes.Clone(); |
| | | 352 | | set |
| | | 353 | | { |
| | 0 | 354 | | ArgumentNullException.ThrowIfNull(value); |
| | | 355 | | |
| | 0 | 356 | | VerifyWritable(); |
| | 0 | 357 | | int[] inputSizes = (int[])value.Clone(); |
| | 0 | 358 | | CheckGroupSize(nameof(value), inputSizes); |
| | 0 | 359 | | _percentGroupSizes = inputSizes; |
| | 0 | 360 | | } |
| | | 361 | | } |
| | | 362 | | |
| | | 363 | | public string CurrencyGroupSeparator |
| | | 364 | | { |
| | 0 | 365 | | get => _currencyGroupSeparator; |
| | | 366 | | set |
| | | 367 | | { |
| | 0 | 368 | | VerifyWritable(); |
| | 0 | 369 | | ArgumentNullException.ThrowIfNull(value); |
| | 0 | 370 | | _currencyGroupSeparator = value; |
| | 0 | 371 | | _currencyGroupSeparatorUtf8 = null; |
| | 0 | 372 | | } |
| | | 373 | | } |
| | | 374 | | |
| | | 375 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 376 | | internal ReadOnlySpan<TChar> CurrencyGroupSeparatorTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 377 | | { |
| | 0 | 378 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 379 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 380 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_currencyGroupSeparator) : |
| | 0 | 381 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _currencyGroupSeparatorUtf8, _cu |
| | | 382 | | } |
| | | 383 | | |
| | | 384 | | public string CurrencySymbol |
| | | 385 | | { |
| | 0 | 386 | | get => _currencySymbol; |
| | | 387 | | set |
| | | 388 | | { |
| | 0 | 389 | | ArgumentNullException.ThrowIfNull(value); |
| | | 390 | | |
| | 0 | 391 | | VerifyWritable(); |
| | 0 | 392 | | _currencySymbol = value; |
| | 0 | 393 | | _currencySymbolUtf8 = null; |
| | 0 | 394 | | } |
| | | 395 | | } |
| | | 396 | | |
| | | 397 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 398 | | internal ReadOnlySpan<TChar> CurrencySymbolTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 399 | | { |
| | 0 | 400 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 401 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 402 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_currencySymbol) : |
| | 0 | 403 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _currencySymbolUtf8, _currencySy |
| | | 404 | | } |
| | | 405 | | |
| | | 406 | | /// <summary> |
| | | 407 | | /// Returns the current culture's NumberFormatInfo. Used by Parse methods. |
| | | 408 | | /// </summary> |
| | | 409 | | |
| | | 410 | | public static NumberFormatInfo CurrentInfo |
| | | 411 | | { |
| | | 412 | | get |
| | | 413 | | { |
| | 0 | 414 | | CultureInfo culture = CultureInfo.CurrentCulture; |
| | 0 | 415 | | if (!culture._isInherited) |
| | | 416 | | { |
| | 0 | 417 | | NumberFormatInfo? info = culture._numInfo; |
| | 0 | 418 | | if (info != null) |
| | | 419 | | { |
| | 0 | 420 | | return info; |
| | | 421 | | } |
| | | 422 | | } |
| | | 423 | | // returns non-nullable when passed typeof(NumberFormatInfo) |
| | 0 | 424 | | return (NumberFormatInfo)culture.GetFormat(typeof(NumberFormatInfo))!; |
| | | 425 | | } |
| | | 426 | | } |
| | | 427 | | |
| | | 428 | | public string NaNSymbol |
| | | 429 | | { |
| | 0 | 430 | | get => _nanSymbol; |
| | | 431 | | set |
| | | 432 | | { |
| | 0 | 433 | | ArgumentNullException.ThrowIfNull(value); |
| | | 434 | | |
| | 0 | 435 | | VerifyWritable(); |
| | 0 | 436 | | _nanSymbol = value; |
| | 0 | 437 | | _nanSymbolUtf8 = null; |
| | 0 | 438 | | } |
| | | 439 | | } |
| | | 440 | | |
| | | 441 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 442 | | internal ReadOnlySpan<TChar> NaNSymbolTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 443 | | { |
| | 0 | 444 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 445 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 446 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_nanSymbol) : |
| | 0 | 447 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _nanSymbolUtf8, _nanSymbol)); |
| | | 448 | | } |
| | | 449 | | |
| | | 450 | | public int CurrencyNegativePattern |
| | | 451 | | { |
| | 0 | 452 | | get => _currencyNegativePattern; |
| | | 453 | | set |
| | | 454 | | { |
| | 0 | 455 | | if (value < 0 || value > 16) |
| | | 456 | | { |
| | 0 | 457 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 16); |
| | | 458 | | } |
| | | 459 | | |
| | 0 | 460 | | VerifyWritable(); |
| | 0 | 461 | | _currencyNegativePattern = value; |
| | 0 | 462 | | } |
| | | 463 | | } |
| | | 464 | | |
| | | 465 | | public int NumberNegativePattern |
| | | 466 | | { |
| | 0 | 467 | | get => _numberNegativePattern; |
| | | 468 | | set |
| | | 469 | | { |
| | | 470 | | // NOTENOTE: the range of value should correspond to negNumberFormats[] in vm\COMNumber.cpp. |
| | 0 | 471 | | if (value < 0 || value > 4) |
| | | 472 | | { |
| | 0 | 473 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 4); |
| | | 474 | | } |
| | | 475 | | |
| | 0 | 476 | | VerifyWritable(); |
| | 0 | 477 | | _numberNegativePattern = value; |
| | 0 | 478 | | } |
| | | 479 | | } |
| | | 480 | | |
| | | 481 | | public int PercentPositivePattern |
| | | 482 | | { |
| | 0 | 483 | | get => _percentPositivePattern; |
| | | 484 | | set |
| | | 485 | | { |
| | | 486 | | // NOTENOTE: the range of value should correspond to posPercentFormats[] in vm\COMNumber.cpp. |
| | 0 | 487 | | if (value < 0 || value > 3) |
| | | 488 | | { |
| | 0 | 489 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 3); |
| | | 490 | | } |
| | | 491 | | |
| | 0 | 492 | | VerifyWritable(); |
| | 0 | 493 | | _percentPositivePattern = value; |
| | 0 | 494 | | } |
| | | 495 | | } |
| | | 496 | | |
| | | 497 | | public int PercentNegativePattern |
| | | 498 | | { |
| | 0 | 499 | | get => _percentNegativePattern; |
| | | 500 | | set |
| | | 501 | | { |
| | | 502 | | // NOTENOTE: the range of value should correspond to posPercentFormats[] in vm\COMNumber.cpp. |
| | 0 | 503 | | if (value < 0 || value > 11) |
| | | 504 | | { |
| | 0 | 505 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 11); |
| | | 506 | | } |
| | | 507 | | |
| | 0 | 508 | | VerifyWritable(); |
| | 0 | 509 | | _percentNegativePattern = value; |
| | 0 | 510 | | } |
| | | 511 | | } |
| | | 512 | | |
| | | 513 | | public string NegativeInfinitySymbol |
| | | 514 | | { |
| | 0 | 515 | | get => _negativeInfinitySymbol; |
| | | 516 | | set |
| | | 517 | | { |
| | 0 | 518 | | ArgumentNullException.ThrowIfNull(value); |
| | | 519 | | |
| | 0 | 520 | | VerifyWritable(); |
| | 0 | 521 | | _negativeInfinitySymbol = value; |
| | 0 | 522 | | _negativeInfinitySymbolUtf8 = null; |
| | 0 | 523 | | } |
| | | 524 | | } |
| | | 525 | | |
| | | 526 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 527 | | internal ReadOnlySpan<TChar> NegativeInfinitySymbolTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 528 | | { |
| | 0 | 529 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 530 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 531 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_negativeInfinitySymbol) : |
| | 0 | 532 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _negativeInfinitySymbolUtf8, _ne |
| | | 533 | | } |
| | | 534 | | |
| | | 535 | | public string NegativeSign |
| | | 536 | | { |
| | 0 | 537 | | get => _negativeSign; |
| | | 538 | | set |
| | | 539 | | { |
| | 0 | 540 | | ArgumentNullException.ThrowIfNull(value); |
| | | 541 | | |
| | 0 | 542 | | VerifyWritable(); |
| | 0 | 543 | | _negativeSign = value; |
| | 0 | 544 | | _negativeSignUtf8 = null; |
| | 0 | 545 | | InitializeInvariantAndNegativeSignFlags(); |
| | 0 | 546 | | } |
| | | 547 | | } |
| | | 548 | | |
| | | 549 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 550 | | internal ReadOnlySpan<TChar> NegativeSignTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 551 | | { |
| | 0 | 552 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 553 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 554 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_negativeSign) : |
| | 0 | 555 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _negativeSignUtf8, _negativeSign |
| | | 556 | | } |
| | | 557 | | |
| | | 558 | | public int NumberDecimalDigits |
| | | 559 | | { |
| | 0 | 560 | | get => _numberDecimalDigits; |
| | | 561 | | set |
| | | 562 | | { |
| | 0 | 563 | | if (value < 0 || value > 99) |
| | | 564 | | { |
| | 0 | 565 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 99); |
| | | 566 | | } |
| | | 567 | | |
| | 0 | 568 | | VerifyWritable(); |
| | 0 | 569 | | _numberDecimalDigits = value; |
| | 0 | 570 | | } |
| | | 571 | | } |
| | | 572 | | |
| | | 573 | | public string NumberDecimalSeparator |
| | | 574 | | { |
| | 0 | 575 | | get => _numberDecimalSeparator; |
| | | 576 | | set |
| | | 577 | | { |
| | 0 | 578 | | VerifyWritable(); |
| | 0 | 579 | | ArgumentException.ThrowIfNullOrEmpty(value); |
| | 0 | 580 | | _numberDecimalSeparator = value; |
| | 0 | 581 | | _numberDecimalSeparatorUtf8 = null; |
| | 0 | 582 | | } |
| | | 583 | | } |
| | | 584 | | |
| | | 585 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 586 | | internal ReadOnlySpan<TChar> NumberDecimalSeparatorTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 587 | | { |
| | 0 | 588 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 589 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 590 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_numberDecimalSeparator) : |
| | 0 | 591 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _numberDecimalSeparatorUtf8, _nu |
| | | 592 | | } |
| | | 593 | | |
| | | 594 | | public string NumberGroupSeparator |
| | | 595 | | { |
| | 0 | 596 | | get => _numberGroupSeparator; |
| | | 597 | | set |
| | | 598 | | { |
| | 0 | 599 | | VerifyWritable(); |
| | 0 | 600 | | ArgumentNullException.ThrowIfNull(value); |
| | 0 | 601 | | _numberGroupSeparator = value; |
| | 0 | 602 | | _numberGroupSeparatorUtf8 = null; |
| | 0 | 603 | | } |
| | | 604 | | } |
| | | 605 | | |
| | | 606 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 607 | | internal ReadOnlySpan<TChar> NumberGroupSeparatorTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 608 | | { |
| | 0 | 609 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 610 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 611 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_numberGroupSeparator) : |
| | 0 | 612 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _numberGroupSeparatorUtf8, _numb |
| | | 613 | | } |
| | | 614 | | |
| | | 615 | | public int CurrencyPositivePattern |
| | | 616 | | { |
| | 0 | 617 | | get => _currencyPositivePattern; |
| | | 618 | | set |
| | | 619 | | { |
| | 0 | 620 | | if (value < 0 || value > 3) |
| | | 621 | | { |
| | 0 | 622 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 3); |
| | | 623 | | } |
| | | 624 | | |
| | 0 | 625 | | VerifyWritable(); |
| | 0 | 626 | | _currencyPositivePattern = value; |
| | 0 | 627 | | } |
| | | 628 | | } |
| | | 629 | | |
| | | 630 | | public string PositiveInfinitySymbol |
| | | 631 | | { |
| | 0 | 632 | | get => _positiveInfinitySymbol; |
| | | 633 | | set |
| | | 634 | | { |
| | 0 | 635 | | ArgumentNullException.ThrowIfNull(value); |
| | | 636 | | |
| | 0 | 637 | | VerifyWritable(); |
| | 0 | 638 | | _positiveInfinitySymbol = value; |
| | 0 | 639 | | _positiveInfinitySymbolUtf8 = null; |
| | 0 | 640 | | } |
| | | 641 | | } |
| | | 642 | | |
| | | 643 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 644 | | internal ReadOnlySpan<TChar> PositiveInfinitySymbolTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 645 | | { |
| | 0 | 646 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 647 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 648 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_positiveInfinitySymbol) : |
| | 0 | 649 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _positiveInfinitySymbolUtf8, _po |
| | | 650 | | } |
| | | 651 | | |
| | | 652 | | public string PositiveSign |
| | | 653 | | { |
| | 0 | 654 | | get => _positiveSign; |
| | | 655 | | set |
| | | 656 | | { |
| | 0 | 657 | | ArgumentNullException.ThrowIfNull(value); |
| | | 658 | | |
| | 0 | 659 | | VerifyWritable(); |
| | 0 | 660 | | _positiveSign = value; |
| | 0 | 661 | | _positiveSignUtf8 = null; |
| | 0 | 662 | | InitializeInvariantAndNegativeSignFlags(); |
| | 0 | 663 | | } |
| | | 664 | | } |
| | | 665 | | |
| | | 666 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 667 | | internal ReadOnlySpan<TChar> PositiveSignTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 668 | | { |
| | 0 | 669 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 670 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 671 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_positiveSign) : |
| | 0 | 672 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _positiveSignUtf8, _positiveSign |
| | | 673 | | } |
| | | 674 | | |
| | | 675 | | public int PercentDecimalDigits |
| | | 676 | | { |
| | 0 | 677 | | get => _percentDecimalDigits; |
| | | 678 | | set |
| | | 679 | | { |
| | 0 | 680 | | if (value < 0 || value > 99) |
| | | 681 | | { |
| | 0 | 682 | | ThrowHelper.ThrowArgumentOutOfRange_Range(nameof(value), value, 0, 99); |
| | | 683 | | } |
| | | 684 | | |
| | 0 | 685 | | VerifyWritable(); |
| | 0 | 686 | | _percentDecimalDigits = value; |
| | 0 | 687 | | } |
| | | 688 | | } |
| | | 689 | | |
| | | 690 | | public string PercentDecimalSeparator |
| | | 691 | | { |
| | 0 | 692 | | get => _percentDecimalSeparator; |
| | | 693 | | set |
| | | 694 | | { |
| | 0 | 695 | | VerifyWritable(); |
| | 0 | 696 | | ArgumentException.ThrowIfNullOrEmpty(value); |
| | 0 | 697 | | _percentDecimalSeparator = value; |
| | 0 | 698 | | _percentDecimalSeparatorUtf8 = null; |
| | 0 | 699 | | } |
| | | 700 | | } |
| | | 701 | | |
| | | 702 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 703 | | internal ReadOnlySpan<TChar> PercentDecimalSeparatorTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 704 | | { |
| | 0 | 705 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 706 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 707 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_percentDecimalSeparator) : |
| | 0 | 708 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _percentDecimalSeparatorUtf8, _p |
| | | 709 | | } |
| | | 710 | | |
| | | 711 | | public string PercentGroupSeparator |
| | | 712 | | { |
| | 0 | 713 | | get => _percentGroupSeparator; |
| | | 714 | | set |
| | | 715 | | { |
| | 0 | 716 | | VerifyWritable(); |
| | 0 | 717 | | ArgumentNullException.ThrowIfNull(value); |
| | 0 | 718 | | _percentGroupSeparator = value; |
| | 0 | 719 | | _percentGroupSeparatorUtf8 = null; |
| | 0 | 720 | | } |
| | | 721 | | } |
| | | 722 | | |
| | | 723 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 724 | | internal ReadOnlySpan<TChar> PercentGroupSeparatorTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 725 | | { |
| | 0 | 726 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 727 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 728 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_percentGroupSeparator) : |
| | 0 | 729 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _percentGroupSeparatorUtf8, _per |
| | | 730 | | } |
| | | 731 | | |
| | | 732 | | public string PercentSymbol |
| | | 733 | | { |
| | 0 | 734 | | get => _percentSymbol; |
| | | 735 | | set |
| | | 736 | | { |
| | 0 | 737 | | ArgumentNullException.ThrowIfNull(value); |
| | 0 | 738 | | VerifyWritable(); |
| | 0 | 739 | | _percentSymbol = value; |
| | 0 | 740 | | _percentSymbolUtf8 = null; |
| | 0 | 741 | | } |
| | | 742 | | } |
| | | 743 | | |
| | | 744 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 745 | | internal ReadOnlySpan<TChar> PercentSymbolTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 746 | | { |
| | 0 | 747 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 748 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 749 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_percentSymbol) : |
| | 0 | 750 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _percentSymbolUtf8, _percentSymb |
| | | 751 | | } |
| | | 752 | | |
| | | 753 | | public string PerMilleSymbol |
| | | 754 | | { |
| | 0 | 755 | | get => _perMilleSymbol; |
| | | 756 | | set |
| | | 757 | | { |
| | 0 | 758 | | ArgumentNullException.ThrowIfNull(value); |
| | | 759 | | |
| | 0 | 760 | | VerifyWritable(); |
| | 0 | 761 | | _perMilleSymbol = value; |
| | 0 | 762 | | _perMilleSymbolUtf8 = null; |
| | 0 | 763 | | } |
| | | 764 | | } |
| | | 765 | | |
| | | 766 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 767 | | internal ReadOnlySpan<TChar> PerMilleSymbolTChar<TChar>() where TChar : unmanaged, IUtfChar<TChar> |
| | | 768 | | { |
| | 0 | 769 | | Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); |
| | 0 | 770 | | return typeof(TChar) == typeof(char) ? |
| | 0 | 771 | | Unsafe.BitCast<ReadOnlySpan<char>, ReadOnlySpan<TChar>>(_perMilleSymbol) : |
| | 0 | 772 | | Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(GetUtf8Span(ref _perMilleSymbolUtf8, _perMilleSy |
| | | 773 | | } |
| | | 774 | | |
| | | 775 | | public string[] NativeDigits |
| | | 776 | | { |
| | 0 | 777 | | get => (string[])_nativeDigits.Clone(); |
| | | 778 | | set |
| | | 779 | | { |
| | 0 | 780 | | VerifyWritable(); |
| | 0 | 781 | | VerifyNativeDigits(value, nameof(value)); |
| | 0 | 782 | | _nativeDigits = value; |
| | 0 | 783 | | } |
| | | 784 | | } |
| | | 785 | | |
| | | 786 | | public DigitShapes DigitSubstitution |
| | | 787 | | { |
| | 0 | 788 | | get => (DigitShapes)_digitSubstitution; |
| | | 789 | | set |
| | | 790 | | { |
| | 0 | 791 | | VerifyWritable(); |
| | 0 | 792 | | VerifyDigitSubstitution(value, nameof(value)); |
| | 0 | 793 | | _digitSubstitution = (int)value; |
| | 0 | 794 | | } |
| | | 795 | | } |
| | | 796 | | |
| | | 797 | | public object? GetFormat(Type? formatType) |
| | | 798 | | { |
| | 0 | 799 | | return formatType == typeof(NumberFormatInfo) ? this : null; |
| | | 800 | | } |
| | | 801 | | |
| | | 802 | | public static NumberFormatInfo ReadOnly(NumberFormatInfo nfi) |
| | | 803 | | { |
| | 0 | 804 | | ArgumentNullException.ThrowIfNull(nfi); |
| | | 805 | | |
| | 0 | 806 | | if (nfi.IsReadOnly) |
| | | 807 | | { |
| | 0 | 808 | | return nfi; |
| | | 809 | | } |
| | | 810 | | |
| | 0 | 811 | | NumberFormatInfo info = (NumberFormatInfo)(nfi.MemberwiseClone()); |
| | 0 | 812 | | info._isReadOnly = true; |
| | 0 | 813 | | return info; |
| | | 814 | | } |
| | | 815 | | |
| | | 816 | | // private const NumberStyles InvalidNumberStyles = unchecked((NumberStyles) 0xFFFFF800); |
| | | 817 | | private const NumberStyles InvalidNumberStyles = ~(NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWh |
| | | 818 | | | NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingS |
| | | 819 | | | NumberStyles.AllowParentheses | NumberStyles.AllowDecimalPo |
| | | 820 | | | NumberStyles.AllowThousands | NumberStyles.AllowExponent |
| | | 821 | | | NumberStyles.AllowCurrencySymbol | NumberStyles.AllowHexSpe |
| | | 822 | | | NumberStyles.AllowBinarySpecifier); |
| | | 823 | | |
| | | 824 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 825 | | internal static void ValidateParseStyleInteger(NumberStyles style) |
| | | 826 | | { |
| | | 827 | | // Check for undefined flags or using AllowHexSpecifier/AllowBinarySpecifier each with anything other than A |
| | 0 | 828 | | if ((style & (InvalidNumberStyles | NumberStyles.AllowHexSpecifier | NumberStyles.AllowBinarySpecifier)) != |
| | 0 | 829 | | (style & ~NumberStyles.HexNumber) != 0 && |
| | 0 | 830 | | (style & ~NumberStyles.BinaryNumber) != 0) |
| | | 831 | | { |
| | 0 | 832 | | ThrowInvalid(style); |
| | | 833 | | |
| | | 834 | | static void ThrowInvalid(NumberStyles value) |
| | | 835 | | { |
| | 0 | 836 | | throw new ArgumentException( |
| | 0 | 837 | | (value & InvalidNumberStyles) != 0 ? SR.Argument_InvalidNumberStyles : SR.Arg_InvalidHexBinarySt |
| | 0 | 838 | | nameof(style)); |
| | | 839 | | } |
| | | 840 | | } |
| | 0 | 841 | | } |
| | | 842 | | |
| | | 843 | | internal static void ValidateParseStyleFloatingPoint(NumberStyles style) |
| | | 844 | | { |
| | | 845 | | // Check for undefined flags, AllowBinarySpecifier (never valid for float), or AllowHexSpecifier with anythi |
| | | 846 | | // When AllowHexSpecifier is specified, AllowExponent must also be specified; this reserves |
| | | 847 | | // AllowHexSpecifier without AllowExponent for possible future use (e.g. optional p exponent). |
| | 0 | 848 | | if ((style & (InvalidNumberStyles | NumberStyles.AllowBinarySpecifier | NumberStyles.AllowHexSpecifier)) != |
| | 0 | 849 | | ((style & ~NumberStyles.HexFloat) != 0 || |
| | 0 | 850 | | (style & NumberStyles.AllowHexSpecifier) != 0 && (style & NumberStyles.AllowExponent) == 0)) |
| | | 851 | | { |
| | 0 | 852 | | ThrowInvalid(style); |
| | | 853 | | |
| | | 854 | | static void ThrowInvalid(NumberStyles value) |
| | | 855 | | { |
| | 0 | 856 | | throw new ArgumentException( |
| | 0 | 857 | | (value & InvalidNumberStyles) != 0 ? SR.Argument_InvalidNumberStyles : |
| | 0 | 858 | | (value & NumberStyles.AllowBinarySpecifier) != 0 ? SR.Arg_BinaryStyleNotSupported : |
| | 0 | 859 | | SR.Arg_InvalidHexFloatStyle, |
| | 0 | 860 | | nameof(style)); |
| | | 861 | | } |
| | | 862 | | } |
| | 0 | 863 | | } |
| | | 864 | | |
| | | 865 | | internal static void ValidateParseStyleDecimal(NumberStyles style) |
| | | 866 | | { |
| | | 867 | | // Check for undefined flags or hex/binary specifiers. |
| | 0 | 868 | | if ((style & (InvalidNumberStyles | NumberStyles.AllowHexSpecifier | NumberStyles.AllowBinarySpecifier)) != |
| | | 869 | | { |
| | 0 | 870 | | ThrowInvalid(style); |
| | | 871 | | |
| | | 872 | | static void ThrowInvalid(NumberStyles value) => |
| | 0 | 873 | | throw new ArgumentException((value & InvalidNumberStyles) != 0 ? SR.Argument_InvalidNumberStyles : S |
| | | 874 | | } |
| | 0 | 875 | | } |
| | | 876 | | } |
| | | 877 | | } |
| | | 878 | | |