Add() public method

Add a byte
public Add ( byte b ) : void
b byte byte data
return void
Ejemplo n.º 1
0
        internal void MergeText()
        {
            var list = new RTFNodeList();
            var myStr = new StringBuilder();
            var buffer = new ByteBuffer();
            //System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //System.Text.Encoding encode = myOwnerDocument.Encoding ;
            foreach (var node in MyNodes)
            {
                if (node.Type == RTFNodeType.Text)
                {
                    AddString(myStr, buffer);
                    myStr.Append(node.Keyword);
                    continue;
                }
                if (node.Type == RTFNodeType.Control
                    && node.Keyword == "\'"
                    && node.HasParameter)
                {
                    buffer.Add((byte) node.Parameter);
                    continue;
                }
                if (node.Type == RTFNodeType.Control || node.Type == RTFNodeType.Keyword)
                {
                    if (node.Keyword == "tab")
                    {
                        AddString(myStr, buffer);
                        myStr.Append('\t');
                        continue;
                    }
                    if (node.Keyword == "emdash")
                    {
                        AddString(myStr, buffer);
                        // notice!! This code may cause compiler error in OS which not support chinese character.
                        // you can change to myStr.Append('-');
                        myStr.Append('j');
                        continue;
                    }
                    if (node.Keyword == "")
                    {
                        AddString(myStr, buffer);
                        // notice!! This code may cause compiler error in OS which not support chinese character.
                        // you can change to myStr.Append('-');
                        myStr.Append('Ƀ');
                        continue;
                    }
                }
                AddString(myStr, buffer);
                if (myStr.Length > 0)
                {
                    list.Add(new RTFNode(RTFNodeType.Text, myStr.ToString()));
                    myStr = new StringBuilder();
                }
                list.Add(node);
            } //foreach( RTFNode node in myNodes )

            AddString(myStr, buffer);
            if (myStr.Length > 0)
            {
                list.Add(new RTFNode(RTFNodeType.Text, myStr.ToString()));
            }
            MyNodes.Clear();
            foreach (var node in list)
            {
                node.Parent = this;
                node.OwnerDocument = MyOwnerDocument;
                MyNodes.Add(node);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Accept rtf token
 /// </summary>
 /// <param name="token">RTF token</param>
 /// <returns>Is accept it?</returns>
 public bool Accept(RTFToken token, RTFReader reader)
 {
     if (token == null)
     {
         return(false);
     }
     if (token.Type == RTFTokenType.Text)
     {
         if (reader != null)
         {
             if (token.Key[0] == '?')
             {
                 if (reader.LastToken != null)
                 {
                     if (reader.LastToken.Type == RTFTokenType.Keyword &&
                         reader.LastToken.Key == "u" &&
                         reader.LastToken.HasParam)
                     {
                         // 紧跟在在“\uN”后面的问号忽略掉
                         if (token.Key.Length > 0)
                         {
                             CheckBuffer();
                             //myStr.Append(token.Key.Substring(1));
                         }
                         return(true);
                     }
                 }
             }
             //else if (token.Key == "\"")
             //{
             //    // 双引号开头,一直读取内容到双引号结束
             //    CheckBuffer();
             //    while (true)
             //    {
             //        int v = reader.InnerReader.Read();
             //        if (v > 0)
             //        {
             //            if (v == (int)'"')
             //            {
             //                break;
             //            }
             //            else
             //            {
             //                myStr.Append((char)v);
             //            }
             //        }
             //        else
             //        {
             //            break;
             //        }
             //    }//while
             //    return true;
             //}
         }
         CheckBuffer();
         myStr.Append(token.Key);
         return(true);
     }
     else if (token.Type == RTFTokenType.Control &&
              token.Key == "'" && token.HasParam)
     {
         if (reader.CurrentLayerInfo.CheckUCValueCount())
         {
             myBuffer.Add((byte)token.Param);
         }
         return(true);
     }
     if (token.Key == RTFConsts._u && token.HasParam)
     {
         // Unicode char
         CheckBuffer();
         // 不忽略 \u 指令
         myStr.Append((char)token.Param);
         reader.CurrentLayerInfo.UCValueCount = reader.CurrentLayerInfo.UCValue;
         return(true);
     }
     if (token.Key == "tab")
     {
         CheckBuffer();
         myStr.Append("\t");
         return(true);
     }
     if (token.Key == "emdash")
     {
         CheckBuffer();
         myStr.Append('—');
         return(true);
     }
     if (token.Key == "")
     {
         // 提示未识别的字符
         CheckBuffer();
         myStr.Append('-');
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        internal void MergeText()
        {
            RTFNodeList list = new RTFNodeList();

            System.Text.StringBuilder myStr = new System.Text.StringBuilder();
            ByteBuffer buffer = new ByteBuffer();

            //System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //System.Text.Encoding encode = myOwnerDocument.Encoding ;
            foreach (RTFNode node in myNodes)
            {
                if (node.Type == RTFNodeType.Text)
                {
                    AddString(myStr, buffer);
                    myStr.Append(node.Keyword);
                    continue;
                }
                if (node.Type == RTFNodeType.Control &&
                    node.Keyword == "\'" &&
                    node.HasParameter)
                {
                    buffer.Add(( byte )node.Parameter);
                    continue;
                }
                else if (node.Type == RTFNodeType.Control || node.Type == RTFNodeType.Keyword)
                {
                    if (node.Keyword == "tab")
                    {
                        AddString(myStr, buffer);
                        myStr.Append('\t');
                        continue;
                    }
                    if (node.Keyword == "emdash")
                    {
                        AddString(myStr, buffer);
                        // notice!! This code may cause compiler error in OS which not support chinese character.
                        // you can change to myStr.Append('-');
                        myStr.Append('j');
                        continue;
                    }
                    if (node.Keyword == "")
                    {
                        AddString(myStr, buffer);
                        // notice!! This code may cause compiler error in OS which not support chinese character.
                        // you can change to myStr.Append('-');
                        myStr.Append('Ƀ');
                        continue;
                    }
                }
                AddString(myStr, buffer);
                if (myStr.Length > 0)
                {
                    list.Add(new RTFNode(RTFNodeType.Text, myStr.ToString()));
                    myStr = new System.Text.StringBuilder();
                }
                list.Add(node);
            }            //foreach( RTFNode node in myNodes )

            AddString(myStr, buffer);
            if (myStr.Length > 0)
            {
                list.Add(new RTFNode(RTFNodeType.Text, myStr.ToString()));
            }
            myNodes.Clear();
            foreach (RTFNode node in list)
            {
                node.Parent        = this;
                node.OwnerDocument = myOwnerDocument;
                myNodes.Add(node);
            }
        }