Menu

#1 Tab char not properly escaped

open
nobody
None
5
2014-08-09
2010-02-25
Damien
No

Hi,

A tab char in a text should be replaced with "\tab" instead of just being escaped.

Here is a piece of code that should work :

        private void InsertText(string text)
        {
            int i = 0;
            int code = 0;

            while (i < text.Length)
            {
                code = Char.ConvertToUtf32(text, i);

                if (code >= 32 && code < 128)
                {
                    StringBuilder s = new StringBuilder("");

                    while (i < text.Length && code >= 32 && code < 128)
                    {
                        s.Append(text[i]);

                        i++;

                        if (i < text.Length)
                            code = Char.ConvertToUtf32(text, i);
                    }

                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Text, s.ToString(), false, 0));
                }
                else
                {
                    if (text[i] == '\t')
                    {
                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Control, "tab", false, 0));
                    }
                    else
                    {
                        byte[] bytes = encoding.GetBytes(new char[] { text[i] });

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Control, "'", true, bytes[0]));
                    }
                    i++;
                }
            }
        }

Discussion


Log in to post a comment.

Auth0 Logo