Exemple #1
0
        public void ByteVector_IndexOf()
        {
            byte[] sample = Enumerable.Range(0, 250).Select((i) => (byte)i).ToArray();

            Assert.AreEqual(0, ByteVector.IndexOf(0, sample, 0, sample.Length));            // First
            Assert.AreEqual(1, ByteVector.IndexOf(1, sample, 0, sample.Length));            // Second
            Assert.AreEqual(200, ByteVector.IndexOf(200, sample, 0, sample.Length));        // Middle
            Assert.AreEqual(249, ByteVector.IndexOf(249, sample, 0, sample.Length));        // Last

            Assert.AreEqual(-1, ByteVector.IndexOf(0, sample, 1, sample.Length));           // Index respected
            Assert.AreEqual(1, ByteVector.IndexOf(1, sample, 1, sample.Length));            // Index respected
            Assert.AreEqual(248, ByteVector.IndexOf(248, sample, 0, sample.Length - 1));    // Index respected
            Assert.AreEqual(-1, ByteVector.IndexOf(249, sample, 0, sample.Length - 1));     // Index respected
        }
Exemple #2
0
        /// <summary>
        /// Get a string from EBML Element's data section (UTF-8).
        /// Handle null-termination.
        /// </summary>
        /// <returns>a string object containing the parsed value.</returns>
        public string GetString()
        {
            if (Data == null)
            {
                return(null);
            }
            var idx = Data.IndexOf(0x00);             // Detected Null termination

            if (idx >= 0)
            {
                return(Data.ToString(StringType.UTF8, 0, idx));
            }
            return(Data.ToString(StringType.UTF8));
        }
Exemple #3
0
        private int LengthIncludingTerminator()
        {
            int readSize      = 16 * 1024;
            int lengthScanned = 0;

            int endIndex = -1;

            while (endIndex == -1)
            {
                // Read a block of bytes
                _reader.EnsureSpace(readSize);

                // Look for the EndValue marker (only *after* previously read bytes)
                endIndex = ByteVector.IndexOf((byte)BionMarker.EndValue, _reader.Buffer, _reader.Index + lengthScanned, _reader.Length);

                // Read more next time (without advancing index)
                lengthScanned = _reader.Length - _reader.Index;
                readSize     *= 2;
            }

            // Return the number of characters to the terminator
            return((endIndex + 1) - _reader.Index);
        }