Support Digit and Decimal values in CharUnicodeInfo
authorTarekm Mahmoud Sayed <tarekms@microsoft.com>
Thu, 22 Sep 2016 16:50:32 +0000 (09:50 -0700)
committerTarekm Mahmoud Sayed <tarekms@microsoft.com>
Thu, 22 Sep 2016 17:18:53 +0000 (10:18 -0700)
This change adding the needed data for the digit and decimal values and the needed code to use the data and return the required values

src/mscorlib/corefx/System/Globalization/CharUnicodeInfo.cs
src/mscorlib/corefx/System/Globalization/CharUnicodeInfoData.cs
src/mscorlib/corefx/System/Globalization/STUBS.cs

index 4cb95fb8f1f723a434c55680c35d6d61c279e176..fc31c7086fca02d0272dd60b5f7f853f485ac0d4 100644 (file)
@@ -191,6 +191,21 @@ namespace System.Globalization
             }
         }
 
+        internal unsafe static ushort InternalGetDigitValues(int ch)
+        {
+            Contract.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
+            // Get the level 2 item from the highest 12 bit (8 - 19) of ch.
+            ushort index = s_pNumericLevel1Index[ch >> 8];
+            // Get the level 2 WORD offset from the 4 - 7 bit of ch.  This provides the base offset of the level 3 table.
+            // Note that & has the lower precedence than addition, so don't forget the parathesis.
+            index = s_pNumericLevel1Index[index + ((ch >> 4) & 0x000f)];
+            
+            fixed (ushort* pUshortPtr = &(s_pNumericLevel1Index[index]))
+            {
+                byte* pBytePtr = (byte*)pUshortPtr;
+                return s_pDigitValues[pBytePtr[(ch & 0x000f)]];
+            }
+        }
 
         ////////////////////////////////////////////////////////////////////////
         //
@@ -228,6 +243,48 @@ namespace System.Globalization
             return (InternalGetNumericValue(InternalConvertToUtf32(s, index)));
         }
 
+        public static int GetDecimalDigitValue(char ch) 
+        {
+            return (sbyte) (InternalGetDigitValues(ch) >> 8);
+        }
+
+        public static int GetDecimalDigitValue(String s, int index) 
+        {
+            if (s == null) 
+            {
+                throw new ArgumentNullException("s");
+            }
+            
+            if (index < 0 || index >= s.Length) 
+            {
+                throw new ArgumentOutOfRangeException("index", SR.ArgumentOutOfRange_Index);
+            }
+            Contract.EndContractBlock();
+
+            return (sbyte) (InternalGetDigitValues(InternalConvertToUtf32(s, index)) >> 8);
+        }
+        
+        public static int GetDigitValue(char ch)
+        {
+            return (sbyte) (InternalGetDigitValues(ch) & 0x00FF);
+        }
+
+        public static int GetDigitValue(String s, int index) 
+        {
+            if (s == null) 
+            {
+                throw new ArgumentNullException("s");
+            }
+            
+            if (index < 0 || index >= s.Length) 
+            {
+                throw new ArgumentOutOfRangeException("index", SR.ArgumentOutOfRange_Index);
+            }
+            
+            Contract.EndContractBlock();
+            return (sbyte) (InternalGetDigitValues(InternalConvertToUtf32(s, index)) & 0x00FF);
+        }
+
         public static UnicodeCategory GetUnicodeCategory(char ch)
         {
             return (InternalGetUnicodeCategory(ch));
index 7284cfd3bce12a414d0b532d4060408f2d21638b..b1bef8146e606879bc06f40b9044b211abca7afb 100644 (file)
@@ -1218,5 +1218,30 @@ namespace System.Globalization
             0x00, 0x00, 0x00, 0x00, 0x80, 0x84, 0x2e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x84, 0xd7, 0x97, 0x41,
             0x00, 0x00, 0x00, 0x20, 0x5f, 0xa0, 0x02, 0x42, 0x00, 0x00, 0x00, 0xa2, 0x94, 0x1a, 0x6d, 0x42
         };
+
+        private static ushort[] s_pDigitValues = new ushort []
+        {
+            0xffff, 0x0000, 0x0101, 0x0202, 0x0303, 0x0404, 0x0505, 0x0606,
+            0x0707, 0x0808, 0x0909, 0xff02, 0xff03, 0xff01, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xff04, 0xff05, 0xff06,
+            0xff07, 0xff08, 0xff09, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xff00, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+            0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000
+        };
+
     }
 }
index 8c85e836d6cbfed5aa5101c0d87b3348fd667b11..f588683a2b94a950fe0ec1cd176334c03339b400 100644 (file)
@@ -19,14 +19,6 @@ namespace System.Globalization
                                 // so they align with the seasons as well as lunar events.
     }
 
-    public static partial class CharUnicodeInfo
-    {
-        public static int GetDecimalDigitValue(char ch) { throw new NotImplementedException(); }
-        public static int GetDecimalDigitValue(string s, int index) { throw new NotImplementedException(); }
-        public static int GetDigitValue(char ch) { throw new NotImplementedException(); }
-        public static int GetDigitValue(string s, int index) { throw new NotImplementedException(); }
-    }
-
     public partial class CompareInfo : System.Runtime.Serialization.IDeserializationCallback
     {
         public int LCID { get { throw new NotImplementedException(); } }