GetDecimalDigitValue() public static method

public static GetDecimalDigitValue ( String s, int index ) : int
s String
index int
return int
 private static void VerifyNativeDigits(string[] nativeDig, string propertyName)
 {
     if (nativeDig == null)
     {
         throw new ArgumentNullException(propertyName, Environment.GetResourceString("ArgumentNull_Array"));
     }
     if (nativeDig.Length != 10)
     {
         throw new ArgumentException(propertyName, Environment.GetResourceString("Argument_InvalidNativeDigitCount"));
     }
     for (int i = 0; i < nativeDig.Length; i++)
     {
         if (nativeDig[i] == null)
         {
             throw new ArgumentNullException(propertyName, Environment.GetResourceString("ArgumentNull_ArrayValue"));
         }
         if (nativeDig[i].Length != 1)
         {
             if (nativeDig[i].Length != 2)
             {
                 throw new ArgumentException(propertyName, Environment.GetResourceString("Argument_InvalidNativeDigitValue"));
             }
             if (!char.IsSurrogatePair(nativeDig[i][0], nativeDig[i][1]))
             {
                 throw new ArgumentException(propertyName, Environment.GetResourceString("Argument_InvalidNativeDigitValue"));
             }
         }
         if ((CharUnicodeInfo.GetDecimalDigitValue(nativeDig[i], 0) != i) && (CharUnicodeInfo.GetUnicodeCategory(nativeDig[i], 0) != UnicodeCategory.PrivateUse))
         {
             throw new ArgumentException(propertyName, Environment.GetResourceString("Argument_InvalidNativeDigitValue"));
         }
     }
 }
 /// <summary>Gets the decimal digit value of the numeric character at the specified index of the specified string.</summary>
 /// <returns>The decimal digit value of the numeric character at the specified index of the specified string.-or- -1, if the character at the specified index of the specified string is not a decimal digit.</returns>
 /// <param name="s">The <see cref="T:System.String" /> containing the Unicode character for which to get the decimal digit value. </param>
 /// <param name="index">The index of the Unicode character for which to get the decimal digit value. </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="s" /> is null. </exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///   <paramref name="index" /> is outside the range of valid indexes in <paramref name="s" />. </exception>
 public static int GetDecimalDigitValue(string s, int index)
 {
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     return(CharUnicodeInfo.GetDecimalDigitValue(s[index]));
 }
Esempio n. 3
0
        static private void VerifyNativeDigits(String [] nativeDig, String propertyName)
        {
            if (nativeDig == null)
            {
                throw new ArgumentNullException(propertyName,
                                                Environment.GetResourceString("ArgumentNull_Array"));
            }

            if (nativeDig.Length != 10)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNativeDigitCount"), propertyName);
            }
            Contract.EndContractBlock();

            for (int i = 0; i < nativeDig.Length; i++)
            {
                if (nativeDig[i] == null)
                {
                    throw new ArgumentNullException(propertyName,
                                                    Environment.GetResourceString("ArgumentNull_ArrayValue"));
                }


                if (nativeDig[i].Length != 1)
                {
                    if (nativeDig[i].Length != 2)
                    {
                        // Not 1 or 2 UTF-16 code points
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNativeDigitValue"), propertyName);
                    }
                    else if (!char.IsSurrogatePair(nativeDig[i][0], nativeDig[i][1]))
                    {
                        // 2 UTF-6 code points, but not a surrogate pair
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNativeDigitValue"), propertyName);
                    }
                }

                if (CharUnicodeInfo.GetDecimalDigitValue(nativeDig[i], 0) != i &&
                    CharUnicodeInfo.GetUnicodeCategory(nativeDig[i], 0) != UnicodeCategory.PrivateUse)
                {
                    // Not the appropriate digit according to the Unicode data properties
                    // (Digit 0 must be a 0, etc.).
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNativeDigitValue"), propertyName);
                }
            }
        }
Esempio n. 4
0
        private static void VerifyNativeDigits(string[] nativeDig, string propertyName)
        {
            if (nativeDig == null)
            {
                throw new ArgumentNullException(propertyName, SR.ArgumentNull_Array);
            }

            if (nativeDig.Length != 10)
            {
                throw new ArgumentException(SR.Argument_InvalidNativeDigitCount, propertyName);
            }

            for (int i = 0; i < nativeDig.Length; i++)
            {
                if (nativeDig[i] == null)
                {
                    throw new ArgumentNullException(propertyName, SR.ArgumentNull_ArrayValue);
                }

                if (nativeDig[i].Length != 1)
                {
                    if (nativeDig[i].Length != 2)
                    {
                        // Not 1 or 2 UTF-16 code points
                        throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName);
                    }
                    else if (!char.IsSurrogatePair(nativeDig[i][0], nativeDig[i][1]))
                    {
                        // 2 UTF-6 code points, but not a surrogate pair
                        throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName);
                    }
                }

                if (CharUnicodeInfo.GetDecimalDigitValue(nativeDig[i], 0) != i &&
                    CharUnicodeInfo.GetUnicodeCategory(nativeDig[i], 0) != UnicodeCategory.PrivateUse)
                {
                    // Not the appropriate digit according to the Unicode data properties
                    // (Digit 0 must be a 0, etc.).
                    throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName);
                }
            }
        }
        /// <summary>Gets the digit value of the specified numeric character.</summary>
        /// <returns>The digit value of the specified numeric character.-or- -1, if the specified character is not a digit.</returns>
        /// <param name="ch">The Unicode character for which to get the digit value. </param>
        public static int GetDigitValue(char ch)
        {
            int decimalDigitValue = CharUnicodeInfo.GetDecimalDigitValue(ch);

            if (decimalDigitValue >= 0)
            {
                return(decimalDigitValue);
            }
            if (ch == '⓪')
            {
                return(0);
            }
            if (ch >= '①' && ch < '⑩')
            {
                return((int)(ch - '⑟'));
            }
            if (ch >= '⑴' && ch < '⑽')
            {
                return((int)(ch - '⑳'));
            }
            if (ch >= '⒈' && ch < '⒑')
            {
                return((int)(ch - '⒇'));
            }
            if (ch >= '⓵' && ch < '⓾')
            {
                return((int)(ch - '⓴'));
            }
            if (ch >= '❶' && ch < '❿')
            {
                return((int)(ch - '❵'));
            }
            if (ch >= '➀' && ch < '➉')
            {
                return((int)(ch - '❿'));
            }
            if (ch >= '➊' && ch < '➓')
            {
                return((int)(ch - '➉'));
            }
            return(-1);
        }