示例#1
0
 protected DynamicContent(bool binary, int capacity)
 {
     if (binary)
     {
         bytebuf = BufferUtility.GetByteBuffer(capacity);
     }
     else
     {
         charbuf = BufferUtility.GetCharBuffer(capacity);
     }
     count = 0;
 }
示例#2
0
 public void Add(char c)
 {
     if (IsBinary) // byte-oriented
     {
         // UTF-8 encoding but without surrogate support
         if (c < 0x80)
         {
             // have at most seven bits
             AddByte((byte)c);
         }
         else if (c < 0x800)
         {
             // 2 char, 11 bits
             AddByte((byte)(0xc0 | (c >> 6)));
             AddByte((byte)(0x80 | (c & 0x3f)));
         }
         else
         {
             // 3 char, 16 bits
             AddByte((byte)(0xe0 | ((c >> 12))));
             AddByte((byte)(0x80 | ((c >> 6) & 0x3f)));
             AddByte((byte)(0x80 | (c & 0x3f)));
         }
     }
     else // char-oriented
     {
         // ensure capacity
         int olen = charbuf.Length; // old length
         if (count >= olen)
         {
             int    nlen = olen * 4; // new length
             char[] obuf = charbuf;
             charbuf = BufferUtility.GetCharBuffer(nlen);
             Array.Copy(obuf, 0, charbuf, 0, olen);
             BufferUtility.Return(obuf);
         }
         charbuf[count++] = c;
     }
 }