Exemplo n.º 1
0
        static protected void CopyNonRichText(ref ParseState ioState, int inIdx)
        {
            int copyLength = ioState.CopyLengthExclusive(inIdx);

            if (copyLength <= 0)
            {
                return;
            }

            StringSlice copySlice = ioState.Input.Substring(ioState.CopyStart, copyLength);

            if (ioState.RichOutput.Length <= 0)
            {
                copySlice = copySlice.TrimStart();
            }

            if (copySlice.Length > 0)
            {
                ioState.Target.AddText((uint)copySlice.Length);
                copySlice.AppendTo(ioState.RichOutput);
                copySlice.AppendTo(ioState.StrippedOutput);
            }

            ioState.CopyStart += copyLength;

            // Debug.LogFormat("[TagStringParser] Copied non-rich text '{0}'", copySlice);
        }
Exemplo n.º 2
0
        public void StringSlice_Basics()
        {
            StringSlice slice = "Hello, there!";

            Assert.Equal(13, slice.Length);
            Assert.Equal('H', slice[0]);
            Assert.Equal(' ', slice[6]);

            Assert.True(slice.StartsWith('H'));
            Assert.False(slice.StartsWith('h'));

            Assert.True(slice.StartsWith("Hello"));
            Assert.False(slice.StartsWith("hello"));
            Assert.True(slice.StartsWith("hello", StringComparison.OrdinalIgnoreCase));

            slice = slice.Substring(7, 3);
            Assert.Equal(3, slice.Length);
            Assert.Equal(0, slice.CompareTo("the"));

            StringBuilder result = new StringBuilder();

            slice.AppendTo(result);
            Assert.Equal(3, result.Length);
            Assert.Equal("the", result.ToString());

            slice = slice.Substring(3);
            Assert.Equal(0, slice.Length);
        }
Exemplo n.º 3
0
        static protected void AddNonRichText(ref ParseState ioState, StringSlice inString)
        {
            if (inString.IsEmpty)
            {
                return;
            }

            if (ioState.RichOutput.Length <= 0)
            {
                inString = inString.TrimStart();
            }

            if (inString.Length > 0)
            {
                ioState.Target.AddText((uint)inString.Length);
                inString.AppendTo(ioState.RichOutput);
                inString.AppendTo(ioState.StrippedOutput);
            }

            // Debug.LogFormat("[TagStringParser] Added non-rich text '{0}'", inString);
        }
Exemplo n.º 4
0
        static protected void CopyRichTag(ref ParseState ioState, int inIdx)
        {
            int copyLength = ioState.CopyLengthExclusive(inIdx);

            if (copyLength <= 0)
            {
                return;
            }

            StringSlice copySlice = ioState.Input.Substring(ioState.CopyStart, copyLength);

            copySlice.AppendTo(ioState.RichOutput);
            ioState.CopyStart += copyLength;

            // Debug.LogFormat("[TagStringParser] Copied rich tag '{0}'", copySlice);
        }
Exemplo n.º 5
0
        static protected void RestartString(ref ParseState ioState, StringSlice inInitial, int inIndex)
        {
            StringSlice originalRemaining = ioState.Input.Substring(inIndex);

            if (originalRemaining.Length <= 0)
            {
                ioState.Input = inInitial;
            }
            else
            {
                inInitial.AppendTo(ioState.RegenBuilder);
                originalRemaining.AppendTo(ioState.RegenBuilder);
                ioState.Input = ioState.RegenBuilder.Flush();
            }

            ioState.CopyStart = 0;
        }
Exemplo n.º 6
0
        static protected void CopyOnlyNonRichText(ref ParseState ioState, StringSlice inString)
        {
            int copyLength = inString.Length;

            if (copyLength <= 0)
            {
                return;
            }

            if (ioState.StrippedOutput.Length <= 0)
            {
                inString = inString.TrimStart();
            }

            if (inString.Length > 0)
            {
                ioState.Target.AddText((uint)inString.Length);
                inString.AppendTo(ioState.StrippedOutput);
            }
        }
Exemplo n.º 7
0
        private void EmptyChecks(StringSlice empty)
        {
            // Length should be zero
            Assert.Equal(0, empty.Length);

            // StartsWith should fail gracefully
            Assert.False(empty.StartsWith(':'));
            Assert.False(empty.StartsWith((StringSlice)":"));

            // CompareTo should fail gracefully
            Assert.Equal(-1, empty.CompareTo(":"));

            // AppendTo shouldn't do anything
            StringBuilder result = new StringBuilder();

            empty.AppendTo(result);
            Assert.Equal(0, result.Length);

            // Substring(0) should work
            StringSlice other = empty.Substring(0);
        }