Ejemplo n.º 1
0
            static void ChunkSubstring(Blob target, int start, ref int count, object chunk, out int chunkLength)
            {
                Debug.Assert(start >= 0);
                Debug.Assert(count > 0);
                AssertChunkObject(chunk);

                switch (chunk)
                {
                case string str:
                    chunkLength = str.Length;

                    if (start < str.Length)
                    {
                        int append = Math.Min(str.Length - start, count);
                        target.AddChunk(str.Substring(start, append));
                        count -= append;
                    }

                    break;

                case byte[] barr:
                    chunkLength = barr.Length;

                    if (start < barr.Length)
                    {
                        int append = Math.Min(barr.Length - start, count);
                        var newarr = new byte[append];
                        Array.Copy(barr, start, newarr, 0, append);
                        target.Add(newarr);     // flags must be set
                        count -= append;
                    }

                    break;

                case Blob b:
                    chunkLength = b.Length;
                    b.Substring(target, start, ref count);
                    break;

                case char[] carr:
                    chunkLength = carr.Length;

                    if (start < carr.Length)
                    {
                        int append = Math.Min(carr.Length - start, count);
                        var newarr = new char[append];
                        Array.Copy(carr, start, newarr, 0, append);
                        target.Add(newarr);     // flags must be set
                        count -= append;
                    }
                    break;

                case BlobChar[] barr:
                    chunkLength = barr.Length;

                    if (start < barr.Length)
                    {
                        int append = Math.Min(barr.Length - start, count);
                        var newarr = new BlobChar[append];
                        Array.Copy(barr, start, newarr, 0, append);
                        target.Add(newarr);     // flags must be set
                        count -= append;
                    }
                    break;

                default:
                    throw new ArgumentException(chunk.GetType().ToString());
                }
            }