GetBytes() private method

private GetBytes ( ) : byte[]
return byte[]
Beispiel #1
0
 /// <summary>
 /// Split a <see cref="String"/> or <see cref="PhpBytes"/> to "upto" bytes at left and the rest or <c>null</c> at right.
 /// </summary>
 private static void SplitData(TextElement data, int upto, out TextElement left, out TextElement right)
 {
     Debug.Assert(upto >= 0);
     //if (this.IsText)
     if (data.IsText)
     {
         string s = data.GetText();
         if (upto < s.Length - 1)
         {
             left = new TextElement(s.Substring(0, upto + 1));
             right = new TextElement(s.Substring(upto + 2));
         }
         else
         {
             left = data;
             right = TextElement.Null;
         }
     }
     else
     {
         Debug.Assert(data.IsBinary);
         var bin = data.GetBytes();
         if (upto < bin.Length - 1)
         {
             byte[] l = new byte[upto + 1], r = new byte[bin.Length - upto - 1];
             Array.Copy(bin, 0, l, 0, upto + 1);
             Array.Copy(bin, upto + 1, r, 0, bin.Length - upto - 1);
             left = new TextElement(l);
             right = new TextElement(r);
         }
         else
         {
             left = data;
             right = TextElement.Null;
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Finds the '\n' in a string or PhpBytes and returns its offset or <c>-1</c>
        /// if not found.
        /// </summary>
        /// <param name="data">Data to scan.</param>
        /// <param name="from">Index of the first character to scan.</param>
        /// <returns></returns>
        private static int FindEoln(TextElement data, int from)
        {
            Debug.Assert(!data.IsNull);

            if (data.IsText)
            {
                return data.GetText().IndexOf('\n', from);
            }
            else
            {
                Debug.Assert(data.IsBinary);
                return Array.IndexOf(data.GetBytes(), (byte)'\n', from);
            }
        }