Ejemplo n.º 1
0
        private string GetFixedText(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(input);
            }

            finalText.Clear();
            RTLSupport.FixRTL(input, finalText, farsi, fixTags, preserveNumbers);
            finalText.Reverse();
            return(finalText.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Fixes rich text tags in input string and returns the result.
        /// </summary>
        public static void Fix(FastStringBuilder text)
        {
            for (int i = 0; i < text.Length; i++)
            {
                FindTag(text, i, out int tagStart, out int tagEnd, out int tagType, out int hashCode);

                // If we couldn't find a tag, end the process
                if (tagType == 0)
                {
                    break;
                }

                switch (tagType)
                {
                case 1:     // Opening tag
                {
                    Tag closingTag = default;

                    // Search and find the closing tag for this
                    bool foundClosingTag = false;
                    for (int j = ClosedTagsHash.Count - 1; j >= 0; j--)
                    {
                        if (ClosedTagsHash[j] == hashCode)
                        {
                            closingTag      = ClosedTags[j];
                            foundClosingTag = true;
                            ClosedTags.RemoveAt(j);
                            ClosedTagsHash.RemoveAt(j);
                            break;
                        }
                    }

                    if (foundClosingTag)
                    {
                        // NOTE: order of execution is important here

                        int openingTagLength = tagEnd - tagStart;
                        int closingTagLength = closingTag.End - closingTag.Start;

                        text.Reverse(tagStart, openingTagLength);
                        text.Reverse(closingTag.Start, closingTagLength);
                    }
                    else
                    {
                        text.Reverse(tagStart, tagEnd - tagStart);
                    }

                    break;
                }

                case 2:     // Closing tag
                {
                    ClosedTags.Add(new Tag(tagStart, tagEnd));
                    ClosedTagsHash.Add(hashCode);
                    break;
                }

                case 3:     // Self contained tag
                {
                    text.Reverse(tagStart, tagEnd - tagStart);
                    break;
                }
                }

                i = tagEnd;
            }
        }