Example #1
0
        public void String8_IndexOf()
        {
            string  binaryName  = "System.Collections.Generic.List";
            String8 binaryName8 = binaryName.TestConvert();

            Assert.AreEqual(binaryName.IndexOf('.'), binaryName8.IndexOf((byte)'.'));
            Assert.AreEqual(binaryName.IndexOf('.', 18), binaryName8.IndexOf((byte)'.', 18));
            Assert.AreEqual(binaryName.LastIndexOf('.'), binaryName8.LastIndexOf((byte)'.'));
            Assert.AreEqual(binaryName.LastIndexOf('.', 18), binaryName8.LastIndexOf((byte)'.', 18));

            string  collections  = "Collections";
            String8 collections8 = collections.TestConvert();

            Assert.AreEqual(binaryName.IndexOf(collections), binaryName8.IndexOf(collections8));
            Assert.AreEqual(binaryName.IndexOf(collections, 7), binaryName8.IndexOf(collections8, 7));
            Assert.AreEqual(binaryName.IndexOf(collections, 8), binaryName8.IndexOf(collections8, 8));

            string  lists  = "Lists";
            String8 lists8 = lists.TestConvert();

            Assert.AreEqual(binaryName.IndexOf(lists), binaryName8.IndexOf(lists8));
            Assert.AreEqual(binaryName.IndexOf(lists, 28), binaryName8.IndexOf(lists8, 28));

            string  list  = "List";
            String8 list8 = list.TestConvert();

            Assert.AreEqual(binaryName.IndexOf(list), binaryName8.IndexOf(list8));
            Assert.AreEqual(binaryName.IndexOf(list, 20), binaryName8.IndexOf(list8, 20));
            Assert.AreEqual(binaryName.IndexOf(list, 28), binaryName8.IndexOf(list8, 28));
        }
Example #2
0
        private String8 Between(String8 text, String8 prefix, String8 suffix)
        {
            // Find (first) prefix
            int index = text.IndexOf(prefix);

            // If prefix not found, return full text
            if (index == -1)
            {
                return(text);
            }

            // If prefix at end of value, return empty
            int afterIndex = index + prefix.Length;

            if (afterIndex >= text.Length)
            {
                return(String8.Empty);
            }

            // Find first suffix after prefix end
            int beforeIndex = text.IndexOf(suffix, afterIndex);

            // If suffix not found, return everything after prefix
            if (beforeIndex == -1)
            {
                return(text.Substring(afterIndex));
            }

            // Otherwise, return between
            return(text.Substring(afterIndex, beforeIndex - afterIndex));
        }
Example #3
0
        public static void WriteHtmlEscaped(String8 value, ITabularWriter writer)
        {
            writer.WriteValueStart();

            int writeFrom = 0;

            while (true)
            {
                // Look for an Html Tag
                int startOfTag = value.IndexOf((byte)'<', writeFrom);
                if (startOfTag == -1)
                {
                    break;
                }

                // Write up to the tag
                writer.WriteValuePart(value.Substring(writeFrom, startOfTag - writeFrom));

                // Find the end of the tag
                int endOfTag = value.IndexOf((byte)'>', startOfTag + 1);
                if (endOfTag == -1)
                {
                    // Error: Unclosed tag, don't write anything else
                    writeFrom = value.Length;
                    break;
                }

                writeFrom = endOfTag + 1;
            }

            // Write the value after the last tag
            writer.WriteValuePart(value.Substring(writeFrom));

            writer.WriteValueEnd();
        }
Example #4
0
        public void String8_IndexOf()
        {
            string  binaryName  = "System.Collections.Generic.List";
            String8 binaryName8 = String8.Convert(binaryName, new byte[String8.GetLength(binaryName)]);

            Assert.AreEqual(binaryName.IndexOf('.'), binaryName8.IndexOf((byte)'.'));
            Assert.AreEqual(binaryName.IndexOf('.', 18), binaryName8.IndexOf((byte)'.', 18));
            Assert.AreEqual(binaryName.LastIndexOf('.'), binaryName8.LastIndexOf((byte)'.'));
            Assert.AreEqual(binaryName.LastIndexOf('.', 18), binaryName8.LastIndexOf((byte)'.', 18));
        }
Example #5
0
        private String8 BeforeFirst(String8 text, String8 value)
        {
            int index = text.IndexOf(value);

            if (index == -1)
            {
                return(text);
            }
            return(text.Substring(0, index));
        }
Example #6
0
        private String8 AfterFirst(String8 text, String8 value)
        {
            int index = text.IndexOf(value);

            if (index == -1)
            {
                return(text);
            }

            int afterIndex = index + value.Length;

            if (afterIndex >= text.Length)
            {
                return(String8.Empty);
            }

            return(text.Substring(afterIndex));
        }