Пример #1
0
        /// <inheritdoc />
        public override StringId ReadStringId()
        {
            // Read the index
            var index = ReadInt32Compact();

            // Check if string already encountered
            if (index > m_maxReadStringIndex)
            {
                // This is a new string
                // Read if string is ascii or UTF-16
                bool isAscii = ReadBoolean();

                // Read the byte length
                int byteLength = ReadInt32Compact();

                CollectionUtilities.GrowArrayIfNecessary(ref m_buffer, byteLength);

                // Read the bytes into the buffer
                Read(m_buffer, 0, byteLength);

                var binaryString = new BinaryStringSegment(m_buffer, 0, byteLength, isAscii);
                var stringId     = m_pathTable.StringTable.AddString(binaryString);

                m_readStrings[(uint)index] = stringId;

                m_maxReadStringIndex = index;
                return(stringId);
            }

            return(m_readStrings[(uint)index]);
        }
Пример #2
0
 private void VerifyEquals(BinaryStringSegment s1, BinaryStringSegment s2)
 {
     XAssert.IsTrue(s1.Equals(s2));
     XAssert.IsTrue(s2.Equals(s1));
     XAssert.IsTrue(s2 == s1);
     XAssert.IsTrue(s1 == s2);
     XAssert.IsFalse(s2 != s1);
     XAssert.IsFalse(s1 != s2);
 }
Пример #3
0
        private void VerifyStringExhaustive(string value, bool isAscii)
        {
            var otherString        = "TEST{" + value + "}SURROUND";
            var otherStringSegment = CreateSegment(otherString, isAscii).Subsegment(5, value.Length);

            var fullSegment      = CreateSegment(value, isAscii);
            var otherFullSegment = CreateSegment(value, isAscii);
            BinaryStringSegment fullUnicodeSegment = default(BinaryStringSegment);

            if (isAscii)
            {
                // Create a unicode version to compare to.
                fullUnicodeSegment = CreateSegment(value, isAscii: false);
                VerifyEquals(fullSegment, fullUnicodeSegment);
                VerifyEquals(otherStringSegment, fullUnicodeSegment);
            }

            VerifyEquals(fullSegment, fullSegment);
            VerifyEquals(fullSegment, otherFullSegment);

            for (int startIndex = 0; startIndex < value.Length; startIndex++)
            {
                XAssert.AreEqual(value[startIndex], fullSegment[startIndex]);
                XAssert.AreEqual(value[startIndex], otherFullSegment[startIndex]);

                for (int length = startIndex; length < value.Length - startIndex; length++)
                {
                    var fullPartialSegment  = CreateSegment(value.Substring(startIndex, length), isAscii);
                    var partialSegment      = fullSegment.Subsegment(startIndex, length);
                    var otherPartialSegment = otherStringSegment.Subsegment(startIndex, length);
                    VerifyEquals(partialSegment, fullPartialSegment);
                    VerifyEquals(otherPartialSegment, fullPartialSegment);
                }
            }

            if (isAscii)
            {
                // Verify the Unicode binary segment for the ascii-only character string
                for (int startIndex = 0; startIndex < value.Length; startIndex++)
                {
                    XAssert.AreEqual(value[startIndex], fullUnicodeSegment[startIndex]);

                    for (int length = startIndex; length < value.Length - startIndex; length++)
                    {
                        var fullPartialSegment = CreateSegment(value.Substring(startIndex, length), isAscii);
                        var partialSegment     = CreateSegment(value, isAscii).Subsegment(startIndex, length);
                        VerifyEquals(partialSegment, fullPartialSegment);
                    }
                }
            }
        }
Пример #4
0
        /// <todoc />
        public virtual BinaryStringSegment ReadStringIdValue(InlinedStringKind kind, ref byte[] buffer)
        {
            // This is a new string
            // Read if string is ascii or UTF-16
            bool isAscii = ReadBoolean();

            // Read the byte length
            int byteLength = ReadInt32Compact();

            CollectionUtilities.GrowArrayIfNecessary(ref buffer, byteLength);

            // Read the bytes into the buffer
            Read(buffer, 0, byteLength);

            var binaryString = new BinaryStringSegment(buffer, 0, byteLength, isAscii);

            return(binaryString);
        }