Example #1
0
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong

    public bool NegTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest1: The enumerator is positioned before the first text element of the string.");
        try
        {
            String myString = "\uD800\uDC00\u0061\u0300\u00C6";
            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);
            myTEE.Reset();
            string acutalValue = null;
            acutalValue = myTEE.Current.ToString();
            TestLibrary.TestFramework.LogError("101.1", " InvalidOperationException should be caught.");
            retVal = false;
        }
        catch (InvalidOperationException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("101.0", "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
Example #2
0
        public void PosTest1()
        {
            // Creates and initializes a String containing the following:
            //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
            //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
            //   - a base character (the ligature "")
            String myString = "\uD800\uDC00\u0061\u0300\u00C6";

            string[] expectValue = new string[5];
            expectValue[0] = "\uD800\uDC00";
            expectValue[1] = "\uD800\uDC00";
            expectValue[2] = "\u0061\u0300";
            expectValue[3] = "\u0061\u0300";
            expectValue[4] = "\u00C6";
            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);

            myTEE.Reset();
            string actualValue = null;

            while (myTEE.MoveNext())
            {
                actualValue = myTEE.GetTextElement();
                Assert.Equal(expectValue[myTEE.ElementIndex], actualValue);
            }
        }
        public static bool ContainsEmoji(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            TextElementEnumerator elementEnumerator = StringInfo.GetTextElementEnumerator(str);
            bool flag1 = elementEnumerator.MoveNext();

            while (flag1)
            {
                string textElement1 = elementEnumerator.GetTextElement();
                string hexString1   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1));
                if (hexString1 == "")
                {
                    flag1 = elementEnumerator.MoveNext();
                }
                else
                {
                    bool flag2        = true;
                    bool flag3        = BrowserNavigationService._flagsPrefixes.Contains(hexString1);
                    int  elementIndex = elementEnumerator.ElementIndex;
                    if ((flag3 || BrowserNavigationService._modificatableSmiles.Contains(hexString1)) && elementEnumerator.MoveNext())
                    {
                        string textElement2 = elementEnumerator.GetTextElement();
                        string hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                        if (hexString2 == "" && elementEnumerator.MoveNext())
                        {
                            textElement2 = elementEnumerator.GetTextElement();
                            hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                        }
                        if (hexString2 != "" && (flag3 || BrowserNavigationService._smilesModificators.Contains(hexString2)))
                        {
                            flag2         = false;
                            hexString1   += hexString2;
                            textElement1 += textElement2;
                        }
                        else
                        {
                            elementEnumerator.Reset();
                            elementEnumerator.MoveNext();
                            while (elementEnumerator.ElementIndex != elementIndex)
                            {
                                elementEnumerator.MoveNext();
                            }
                        }
                    }
                    if (flag2)
                    {
                        BrowserNavigationService.CheckRelationsSmiles(ref hexString1, ref elementEnumerator, ref textElement1);
                    }
                    if (Emoji.Dict.ContainsKey(hexString1))
                    {
                        return(true);
                    }
                    flag1 = elementEnumerator.MoveNext();
                }
            }
            return(false);
        }
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong

    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Calling Reset method.");
        try
        {
            // Creates and initializes a String containing the following:
            //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
            //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
            //   - a base character (the ligature "")
            String myString = "\uD800\uDC00\u0061\u0300\u00C6";
            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);
            myTEE.Reset();
            myTEE.MoveNext();
            if (myTEE.ElementIndex != 0)
            {
                TestLibrary.TestFramework.LogError("001.1", " Calling Reset method ,the ElementIndex should return 0.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
        public void AccessingMembersAfterReset_ThrowsInvalidOperationException()
        {
            TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("abc");

            enumerator.MoveNext();

            // Cannot access Current, ElementIndex or GetTextElement() after the enumerator has been reset
            enumerator.Reset();
            Assert.Throws <InvalidOperationException>(() => enumerator.Current);
            Assert.Throws <InvalidOperationException>(() => enumerator.ElementIndex);
            Assert.Throws <InvalidOperationException>(() => enumerator.GetTextElement());
        }
        static void Main(string[] args)
        {
            string myString             = "\uD800\uDC00\u0061\u0300\u00C6";
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);

            Console.WriteLine("Index\tCurrent\tGetTexElement");
            myTEE.Reset();
            while (myTEE.MoveNext())
            {
                Console.WriteLine("[{0}]:\t{1}\t{2}", myTEE.ElementIndex, myTEE.Current, myTEE.GetTextElement());
            }
        }
Example #7
0
        public void NegTest1()
        {
            String myString = "\uD800\uDC00\u0061\u0300\u00C6";
            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);

            myTEE.Reset();
            Assert.Throws <InvalidOperationException>(() =>
            {
                int actualValue = myTEE.ElementIndex;
            });
        }
        public void PosTest1()
        {
            // Creates and initializes a String containing the following:
            //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
            //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
            //   - a base character (the ligature "")
            String myString = "\uD800\uDC00\u0061\u0300\u00C6";
            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);

            myTEE.Reset();
            myTEE.MoveNext();
            Assert.Equal(0, myTEE.ElementIndex);
        }
Example #9
0
        public void NegTest2()
        {
            String myString = "\uD800\uDC00\u0061\u0300\u00C6";

            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);

            myTEE.Reset();
            string actualValue = null;

            while (myTEE.MoveNext())
            {
                actualValue = myTEE.Current.ToString();
            }
            Assert.Throws <InvalidOperationException>(() =>
            {
                actualValue = myTEE.Current.ToString();
            });
        }
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong

    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Calling MoveNext method.");
        try
        {
            // Creates and initializes a String containing the following:
            //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
            //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
            //   - a base character (the ligature "")
            String   myString    = "\uD800\uDC00\u0061\u0300\u00C6";
            string[] expectValue = new string[5];
            expectValue[0] = "\uD800\uDC00";
            expectValue[1] = "\uD800\uDC00";
            expectValue[2] = "\u0061\u0300";
            expectValue[3] = "\u0061\u0300";
            expectValue[4] = "\u00C6";
            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);
            myTEE.Reset();
            string acutalValue = null;
            int    i           = 0;
            while (myTEE.MoveNext())
            {
                acutalValue = myTEE.GetTextElement();
                if (acutalValue != expectValue[myTEE.ElementIndex])
                {
                    TestLibrary.TestFramework.LogError("001." + (i + 1).ToString(), " after Calling MoveNext, GetTextElement method should return " + expectValue[i]);
                    retVal = false;
                    i++;
                }
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
Example #11
0
        public void Enumerate(string[] expectedElements)
        {
            TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(string.Concat(expectedElements));

            for (int i = 0; i < 2; i++)
            {
                int charsProcessedSoFar = 0;

                foreach (string expectedElement in expectedElements)
                {
                    Assert.True(enumerator.MoveNext());
                    Assert.Equal(charsProcessedSoFar, enumerator.ElementIndex);
                    Assert.Equal(expectedElement, enumerator.Current);
                    charsProcessedSoFar += expectedElement.Length;
                }

                Assert.False(enumerator.MoveNext());
                enumerator.Reset();
            }
        }
Example #12
0
    public static void Main()
    {
        // Creates and initializes a String containing the following:
        //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
        //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
        //   - a base character (the ligature "")
        String myString = "\uD800\uDC00\u0061\u0300\u00C6";

        // Creates and initializes a TextElementEnumerator for myString.
        TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);

        // Displays the values returned by ElementIndex, Current and GetTextElement.
        // Current and GetTextElement return a string containing the entire text element.
        Console.WriteLine("Index\tCurrent\tGetTextElement");
        myTEE.Reset();
        while (myTEE.MoveNext())
        {
            Console.WriteLine("[{0}]:\t{1}\t{2}", myTEE.ElementIndex, myTEE.Current, myTEE.GetTextElement());
        }
    }
        public void Enumerate(string str, string[] expectedElements, int[] expectedElementIndices)
        {
            TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(str);

            for (int i = 0; i < 2; i++)
            {
                int counter = 0;
                while (enumerator.MoveNext())
                {
                    string currentTextElement = enumerator.GetTextElement();
                    Assert.Equal(expectedElements[enumerator.ElementIndex], currentTextElement);
                    Assert.Equal(currentTextElement, enumerator.Current);

                    Assert.Equal(expectedElementIndices[counter], enumerator.ElementIndex);
                    counter++;
                }
                Assert.Equal(expectedElementIndices.Length, counter);

                enumerator.Reset();
            }
        }
        public void Enumerate()
        {
            // Creates and initializes a string containing the following:
            //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
            //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
            //   - a base character (the ligature "")
            string[] expectedElements        = new string[] { "\uD800\uDC00", "\uD800\uDC00", "\u0061\u0300", "\u0061\u0300", "\u00C6" };
            int[]    expectedElementIndices  = new int[] { 0, 2, 4 };
            TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("\uD800\uDC00\u0061\u0300\u00C6");

            int counter = 0;

            while (enumerator.MoveNext())
            {
                string currentTextElement = enumerator.GetTextElement();
                Assert.Equal(expectedElements[enumerator.ElementIndex], currentTextElement);
                Assert.Equal(currentTextElement, enumerator.Current);

                Assert.Equal(expectedElementIndices[counter], enumerator.ElementIndex);
                counter++;
            }
            Assert.Equal(expectedElementIndices.Length, counter);

            enumerator.Reset();
            counter = 0;
            while (enumerator.MoveNext())
            {
                string currentTextElement = enumerator.GetTextElement();
                Assert.Equal(expectedElements[enumerator.ElementIndex], currentTextElement);
                Assert.Equal(currentTextElement, enumerator.Current);

                Assert.Equal(expectedElementIndices[counter], enumerator.ElementIndex);
                counter++;
            }
            Assert.Equal(expectedElementIndices.Length, counter);
        }
Example #15
0
        public void PosTest1()
        {
            // Creates and initializes a String containing the following:
            //   - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
            //   - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
            //   - a base character (the ligature "")
            String myString = "\uD800\uDC00\u0061\u0300\u00C6";

            int[] expectValue = new int[3];
            expectValue[0] = 0;
            expectValue[1] = 2;
            expectValue[2] = 4;
            // Creates and initializes a TextElementEnumerator for myString.
            TextElementEnumerator myTEE = StringInfo.GetTextElementEnumerator(myString);

            myTEE.Reset();
            int i = 0;

            while (myTEE.MoveNext())
            {
                Assert.Equal(myTEE.ElementIndex, expectValue[i]);
                i++;
            }
        }
        private static void CheckRelationsSmiles(ref string bytesStr, ref TextElementEnumerator textEnumerator, ref string text)
        {
            bool flag1         = true;
            int  elementIndex1 = textEnumerator.ElementIndex;
            bool flag2         = bytesStr == "D83DDC68";

            if ((flag2 || bytesStr == "D83DDC69") && textEnumerator.MoveNext())
            {
                string textElement1 = textEnumerator.GetTextElement();
                string hexString1   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1));
                if (hexString1 == "" && textEnumerator.MoveNext())
                {
                    textElement1 = textEnumerator.GetTextElement();
                    hexString1   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1));
                }
                if (hexString1 == "2764" && textEnumerator.MoveNext())
                {
                    string textElement2 = textEnumerator.GetTextElement();
                    string hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                    if (hexString2 == "" && textEnumerator.MoveNext())
                    {
                        textElement2 = textEnumerator.GetTextElement();
                        hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                    }
                    string str1 = "";
                    string str2 = "";
                    if (hexString2 == "D83DDC8B" && textEnumerator.MoveNext())
                    {
                        str1         = textElement2;
                        str2         = hexString2;
                        textElement2 = textEnumerator.GetTextElement();
                        hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                        if (hexString2 == "" && textEnumerator.MoveNext())
                        {
                            textElement2 = textEnumerator.GetTextElement();
                            hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                        }
                    }
                    if (flag2 && hexString2 == "D83DDC68" || !flag2 && hexString2 == "D83DDC69")
                    {
                        flag1    = false;
                        bytesStr = bytesStr + hexString1 + str2 + hexString2;
                        text     = text + textElement1 + str1 + textElement2;
                    }
                }
                else if ((hexString1 == "D83DDC68" || hexString1 == "D83DDC69") && (!(bytesStr == "D83DDC69") || !(hexString1 == "D83DDC68")) && textEnumerator.MoveNext())
                {
                    string textElement2 = textEnumerator.GetTextElement();
                    string hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                    if (hexString2 == "" && textEnumerator.MoveNext())
                    {
                        textElement2 = textEnumerator.GetTextElement();
                        hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                    }
                    if (hexString2 == "D83DDC67" || hexString2 == "D83DDC66")
                    {
                        bool flag3         = false;
                        int  elementIndex2 = textEnumerator.ElementIndex;
                        flag1 = false;
                        if (textEnumerator.MoveNext())
                        {
                            string textElement3 = textEnumerator.GetTextElement();
                            string hexString3   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement3));
                            if (hexString3 == "" && textEnumerator.MoveNext())
                            {
                                textElement3 = textEnumerator.GetTextElement();
                                hexString3   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement3));
                            }
                            if ((hexString3 == "D83DDC67" || hexString3 == "D83DDC66") && (!(hexString2 == "D83DDC66") || !(hexString3 == "D83DDC67")))
                            {
                                flag3    = true;
                                bytesStr = bytesStr + hexString1 + hexString2 + hexString3;
                                text     = text + textElement1 + textElement2 + textElement3;
                            }
                            else
                            {
                                textEnumerator.Reset();
                                textEnumerator.MoveNext();
                                while (textEnumerator.ElementIndex != elementIndex2)
                                {
                                    textEnumerator.MoveNext();
                                }
                            }
                        }
                        if (!flag3)
                        {
                            bytesStr = bytesStr + hexString1 + hexString2;
                            text     = text + textElement1 + textElement2;
                        }
                    }
                }
            }
            if (!(textEnumerator.ElementIndex != elementIndex1 & flag1))
            {
                return;
            }
            textEnumerator.Reset();
            textEnumerator.MoveNext();
            while (textEnumerator.ElementIndex != elementIndex1)
            {
                textEnumerator.MoveNext();
            }
        }
        private static void AddRawText(RichTextBox text_block, Paragraph par, string raw_text)
        {
            TextElementEnumerator elementEnumerator = StringInfo.GetTextElementEnumerator(raw_text);
            StringBuilder         stringBuilder     = new StringBuilder();
            bool flag1 = elementEnumerator.MoveNext();

            while (flag1)
            {
                string textElement1 = elementEnumerator.GetTextElement();
                string hexString1   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1));
                if (hexString1 == "")
                {
                    flag1 = elementEnumerator.MoveNext();
                }
                else
                {
                    bool flag2        = true;
                    bool flag3        = BrowserNavigationService._flagsPrefixes.Contains(hexString1);
                    int  elementIndex = elementEnumerator.ElementIndex;
                    if ((flag3 || BrowserNavigationService._modificatableSmiles.Contains(hexString1)) && elementEnumerator.MoveNext())
                    {
                        string textElement2 = elementEnumerator.GetTextElement();
                        string hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                        if (hexString2 == "" && elementEnumerator.MoveNext())
                        {
                            textElement2 = elementEnumerator.GetTextElement();
                            hexString2   = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2));
                        }
                        if (hexString2 != "" && (flag3 || BrowserNavigationService._smilesModificators.Contains(hexString2)))
                        {
                            flag2         = false;
                            hexString1   += hexString2;
                            textElement1 += textElement2;
                        }
                        else
                        {
                            elementEnumerator.Reset();
                            elementEnumerator.MoveNext();
                            while (elementEnumerator.ElementIndex != elementIndex)
                            {
                                elementEnumerator.MoveNext();
                            }
                        }
                    }
                    if (flag2)
                    {
                        BrowserNavigationService.CheckRelationsSmiles(ref hexString1, ref elementEnumerator, ref textElement1);
                    }
                    string name;
                    Emoji.Dict.TryGetValue(hexString1, out name);
                    if (name != null)
                    {
                        string text = stringBuilder.ToString();
                        stringBuilder = stringBuilder.Clear();
                        if (text != string.Empty)
                        {
                            ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)BrowserNavigationService.GetRunWithStyle(text, text_block));
                        }
                        ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)BrowserNavigationService.GetImage(name));
                    }
                    else
                    {
                        stringBuilder = stringBuilder.Append(textElement1);
                    }
                    flag1 = elementEnumerator.MoveNext();
                }
            }
            string text1 = stringBuilder.ToString();

            if (!(text1 != string.Empty))
            {
                return;
            }
            ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)BrowserNavigationService.GetRunWithStyle(text1, text_block));
        }