Ejemplo n.º 1
0
 public void GetNumericValue_Invalid()
 {
     AssertExtensions.Throws <ArgumentNullException>("s", () => CharUnicodeInfo.GetNumericValue(null, 0));
     AssertExtensions.Throws <ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("abc", -1));
     AssertExtensions.Throws <ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("abc", 3));
     AssertExtensions.Throws <ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("", 0));
 }
Ejemplo n.º 2
0
        public static double ConvertUnicodeStringToDecimal(string amountString)
        {
            string parsedString = "";

            for (int i = 0; i < amountString.Length; i++)
            {
                char currChar = amountString[i];
                if (currChar != '.')
                {
                    parsedString += CharUnicodeInfo.GetNumericValue(currChar);
                }
                else
                {
                    parsedString += currChar;
                }
            }

            if (parsedString.Length > 0)
            {
                return(double.Parse(parsedString));
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 3
0
    public bool PosTest3()
    {
        bool retVal = true;

        Char ch = '9';

        Double expectedValue = 9;

        Double actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest1:Test the method with char '9'");
        try
        {
            actualValue = CharUnicodeInfo.GetNumericValue(ch);
            if (expectedValue != actualValue)
            {
                TestLibrary.TestFramework.LogError("005", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
Ejemplo n.º 4
0
    public static string GetUnicodeValue(char c)
    {
        var s = string.Format(" {0,-5}", CharUnicodeInfo.GetNumericValue(c));

        Debug.Log(s);
        return(s);
    }
Ejemplo n.º 5
0
    public bool PosTest2()
    {
        bool retVal = true;

        String str = "\009aZ\u0f33";

        Double expectedValue = 0;

        Double actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest1:Test the method with char '0'");
        try
        {
            actualValue = CharUnicodeInfo.GetNumericValue(str, 1);
            if (expectedValue != actualValue)
            {
                TestLibrary.TestFramework.LogError("003", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
Ejemplo n.º 6
0
 public void GetNumericValue(string s, double[] expected)
 {
     for (int i = 0; i < expected.Length; i++)
     {
         Assert.Equal(expected[i], CharUnicodeInfo.GetNumericValue(s, i));
     }
 }
Ejemplo n.º 7
0
 public static void PrintProperties(char c)
 {
     Console.Write(" {0,-3}", c);
     Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(c));
     Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(c));
     Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(c));
     Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(c));
 }
Ejemplo n.º 8
0
 public static double GetNumericValue(string s, int index)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (((uint)index) >= ((uint)s.Length))
     {
         throw new ArgumentOutOfRangeException(nameof(index));
     }
     return(CharUnicodeInfo.GetNumericValue(s, index));
 }
Ejemplo n.º 9
0
        public void GetNumericValue_Char()
        {
            for (int i = 0; i <= char.MaxValue; i++)
            {
                char ch = (char)i;

                CodePoint knownGoodData = UnicodeData.GetData(ch);
                double    actualValue   = CharUnicodeInfo.GetNumericValue(ch);

                AssertEqual(knownGoodData.NumericValue, actualValue, nameof(CharUnicodeInfo.GetNumericValue), knownGoodData);
            }
        }
Ejemplo n.º 10
0
 public static double GetNumericValue(string s, int index)
 {
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     if (index >= s.Length)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     return(CharUnicodeInfo.GetNumericValue(s, index));
 }
    public static void Main()
    {
        // The String to get information for.
        String s = "a9\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788";

        Console.WriteLine("String: {0}", s);

        // Print the values for each of the characters in the string.
        Console.WriteLine("index c  Num   Dig   Dec   UnicodeCategory");
        for (int i = 0; i < s.Length; i++)
        {
            Console.Write("{0,-5} {1,-3}", i, s[i]);
            Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(s, i));
            Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(s, i));
            Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(s, i));
            Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(s, i));
        }
    }
Ejemplo n.º 12
0
        private static int findDigits(int n)
        {
            int divisors = 0;

            foreach (var item in n.ToString().ToCharArray())
            {
                int num = (int)CharUnicodeInfo.GetNumericValue(item);
                if (num == 0)
                {
                    continue;
                }

                if (n % num == 0)
                {
                    divisors++;
                }
            }
            return(divisors);
        }
Ejemplo n.º 13
0
        public Evaluation Evaluate(ExpressionOptions options, Token token)
        {
            if (token is ListToken listToken)
            {
                return(EvaluateList(options, listToken.Children));
            }

            if (token is ValueToken valueToken)
            {
                string value = valueToken.Value;
                switch (valueToken.Type)
                {
                case TokenType.DecimalDigit:
                    return(new Evaluation(CharUnicodeInfo.GetNumericValue(value[0])));

                case TokenType.DecimalNumber:
                    if (value.Length == 1)
                    {
                        return(new Evaluation(CharUnicodeInfo.GetNumericValue(value[0])));
                    }
                    else
                    {
                        var parsed = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                        return(new Evaluation(parsed));
                    }

                case TokenType.Name:
                    return(ResolveReference.Invoke(valueToken.Value));

                default:
                    return(new Evaluation(EErrorCode.SyntaxError));
                }
            }
            else if (token is FunctionToken funcToken)
            {
                return(EvaluateFunction(options, funcToken));
            }
            return(new Evaluation(EErrorCode.Undefined));
        }
Ejemplo n.º 14
0
    public bool NegTest3()
    {
        bool retVal = true;

        String str         = TestLibrary.Generator.GetString(-55, false, 1, 5);
        Double actureValue = 0;

        TestLibrary.TestFramework.BeginScenario("NegTest1:Invoke the method with index out of right range");
        try
        {
            actureValue = CharUnicodeInfo.GetNumericValue(str, 5);
            TestLibrary.TestFramework.LogError("014", "No ArgumentNullExcepthion thrown out expected.");
            retVal = false;
        }
        catch (ArgumentOutOfRangeException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("015", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
Ejemplo n.º 15
0
    public bool NegTest1()
    {
        bool retVal = true;

        String str         = null;
        Double actureValue = 0;

        TestLibrary.TestFramework.BeginScenario("NegTest1:Invoke the method with null string");
        try
        {
            actureValue = CharUnicodeInfo.GetNumericValue(str, 0);
            TestLibrary.TestFramework.LogError("013", "No ArgumentNullExcepthion thrown out expected.");
            retVal = false;
        }
        catch (ArgumentNullException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("014", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
        internal string MakeAnchorName(string heading)
        {
            /* To be a valid anchor name, first character *must*
             * be a letter.  Subsequent charaters may additionally include:
             * numbers, '-', '_', ':' and '.'
             * */
            var plainText = _htmlStripper.RemoveHtml(heading).Normalize(NormalizationForm.FormD);

            if (String.IsNullOrWhiteSpace(plainText))
            {
                return(String.Empty);
            }

            var anchorName = new StringBuilder();

            var enumerator = plainText.GetEnumerator();

            enumerator.Reset();
            // First character must be a letter
            while (enumerator.MoveNext())
            {
                if (IsRomanLetter(enumerator.Current))
                {
                    anchorName.Append(enumerator.Current);
                    break;
                }
            }

            while (enumerator.MoveNext())
            {
                char c             = enumerator.Current;
                var  lastCharacter = anchorName[anchorName.Length - 1];

                switch (CharUnicodeInfo.GetUnicodeCategory(c))
                {
                case UnicodeCategory.UppercaseLetter:
                case UnicodeCategory.LowercaseLetter:
                    if (IsRomanLetter(c))
                    {
                        anchorName.Append(c);
                    }
                    //TODO: Replace non roman characters with transliterated version
                    break;

                case UnicodeCategory.DecimalDigitNumber:
                case UnicodeCategory.OtherNumber:
                    double number = CharUnicodeInfo.GetNumericValue(c);
                    if (number != -1.0)
                    {
                        anchorName.Append(number);
                    }
                    break;

                case UnicodeCategory.ConnectorPunctuation:
                case UnicodeCategory.DashPunctuation:
                    if (lastCharacter == '_')
                    {
                        anchorName[anchorName.Length - 1] = '-';
                    }
                    else if (lastCharacter != '-')
                    {
                        anchorName.Append('-');
                    }
                    break;

                case UnicodeCategory.OtherPunctuation:
                case UnicodeCategory.SpaceSeparator:
                    if ((lastCharacter != '_') && (lastCharacter != '-'))
                    {
                        anchorName.Append('_');
                    }
                    break;
                }
            }

            while (anchorName.Length != 0 && !char.IsLetterOrDigit(anchorName[anchorName.Length - 1]))
            {
                anchorName.Remove(anchorName.Length - 1, 1);
            }

            return(anchorName.Length == 0 ?
                   "T_" + _random.Next(1000, int.MaxValue)
                                : anchorName.ToString());
        }
Ejemplo n.º 17
0
 public static double GetNumericValue(char c)
 {
     return(CharUnicodeInfo.GetNumericValue(c));
 }
Ejemplo n.º 18
0
        public void GetNumericValue(char ch, double expected)
        {
            double actual = CharUnicodeInfo.GetNumericValue(ch);

            Assert.True(expected == actual, ErrorMessage(ch, expected, actual));
        }
Ejemplo n.º 19
0
Archivo: Rune.cs Proyecto: BaisilG/Core
 public static Double GetNumericValue(Rune value) => CharUnicodeInfo.GetNumericValue(value.ToString(), 0);