示例#1
0
        /// <summary>
        /// Reads a property list (key and element pairs) from a text reader.
        /// </summary>
        /// <param name="dictionary">the dictionary to put it in</param>
        /// <param name="textReader">The text reader to load from.</param>
        public static void Load(IDictionary dictionary, TextReader textReader)
        {
            bool   isContinuation = false;
            string key            = null;
            string value          = null;
            string line           = null;

            while ((line = textReader.ReadLine()) != null)
            {
                line = RemoveLeadingWhitespace(line);
                if (line != null && line.Length > 0 && Comments.IndexOf(line[0]) == -1)
                {
                    if (!isContinuation)
                    {
                        string[] keyvalue = SplitLine(line);
                        if (keyvalue == null)
                        {
                            continue;
                        }
                        key   = keyvalue[0];
                        value = keyvalue[1];

                        if (value != null && value.EndsWith("\\"))
                        {
                            value          = value.Substring(0, value.Length - 1);
                            isContinuation = true;
                        }
                        else
                        {
                            dictionary[key] = StringUtils.ConvertEscapedCharacters(value);
                        }
                    }
                    else
                    {
                        if (line.EndsWith("\\"))
                        {
                            value += line.Substring(0, line.Length - 1);
                        }
                        else
                        {
                            value          += line;
                            isContinuation  = false;
                            dictionary[key] = StringUtils.ConvertEscapedCharacters(value);
                        }
                    }
                }
            }
        }
示例#2
0
        public void ConvertEscapedCharactersAll()
        {
            string inputString = "newline\\n tab\\t return\\r";

            Assert.AreEqual("newline\n tab\t return\r", StringUtils.ConvertEscapedCharacters(inputString));
        }
示例#3
0
        public void ConvertUnsupportedEscapedCharacters()
        {
            string inputString = "what is this\\g";

            Assert.AreEqual(inputString, StringUtils.ConvertEscapedCharacters(inputString));
        }
示例#4
0
        public void ConvertEscapedCharactersNoEscapedCharacters()
        {
            string inputString = "foo bar is a funny term";

            Assert.AreEqual(inputString, StringUtils.ConvertEscapedCharacters(inputString));
        }