예제 #1
0
        /// <summary>
        /// Parses the specified text for configuration entries.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public IList <ConfigLine> Parse(string text)
        {
            var results = new List <ConfigLine>();

            var lines   = text.Split(Environment.NewLine);
            var section = string.Empty;

            foreach (var line in lines)
            {
                // only process lines if content
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                // section header?
                if (line.StartsWith("["))
                {
                    section = line.SubstringAfterChar("[").SubstringBeforeLastChar("]");

                    continue;
                }

                ConfigLine result;

                if (ConfigLine.TryParse(line, out result, section: section))
                {
                    results.Add(result);
                }
            }

            return(results);
        }
예제 #2
0
        public void TestParseConfigLineWhenAComnentWithInvalidIndicator()
        {
            const string input = @"//comment";

            ConfigLine line;

            Assert.Throws <ArgumentException>(() => ConfigLine.TryParse(input, out line, ""));
        }
예제 #3
0
        public void TestParseConfigLineWithEqualsInValue()
        {
            const string input = "test=value=something";

            ConfigLine line;

            ConfigLine.TryParse(input, out line);

            Assert.AreEqual("value=something", line.Value);
        }
예제 #4
0
        public void TestParseConfigLineSetSectionName()
        {
            const string input = "test=value";

            ConfigLine line;

            ConfigLine.TryParse(input, out line, section: "Main");

            Assert.AreEqual("Main", line.Section);
        }
예제 #5
0
        public void TestParseConfigLineWithNoEqualsInValue()
        {
            const string input = "test value is here";

            ConfigLine line;

            ConfigLine.TryParse(input, out line);

            Assert.AreEqual("test value is here", line.Key);
            Assert.AreEqual("", line.Value);
        }
예제 #6
0
        public void TestParseConfigLine()
        {
            const string input = "test=value";

            ConfigLine line;

            var result = ConfigLine.TryParse(input, out line);

            Assert.IsTrue(result);
            Assert.AreEqual("test", line.Key);
            Assert.AreEqual("value", line.Value);
            Assert.IsFalse(line.IsComment);
        }
예제 #7
0
        public void TestParseConfigLineWhenAComnentWithDifferentIndicator()
        {
            const string input = @"//comment";

            ConfigLine line;

            var result = ConfigLine.TryParse(input, out line, @"//");

            Assert.IsTrue(result);
            Assert.AreEqual(string.Empty, line.Key);
            Assert.AreEqual("comment", line.Value);
            Assert.IsTrue(line.IsComment);
        }
예제 #8
0
        public void TestParseConfigLineWhenAComnent()
        {
            const string input = "#comment";

            ConfigLine line;

            var result = ConfigLine.TryParse(input, out line);

            Assert.IsTrue(result);
            Assert.AreEqual(string.Empty, line.Key);
            Assert.AreEqual("comment", line.Value);
            Assert.IsTrue(line.IsComment);
        }