Pchp.Library.Streams.PhpStream.SplitData C# (CSharp) Method

SplitData() private static method

Split a String or PhpBytes to "upto" bytes at left and the rest or null at right.
private static SplitData ( TextElement data, int upto, TextElement &left, TextElement &right ) : void
data TextElement
upto int
left TextElement
right TextElement
return void
        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;
                }
            }
        }

Same methods

PhpStream::SplitData ( string s, int upto, string &left, string &right ) : void