Exemple #1
0
        /// <summary>
        /// Gets INI key-value pair from line of text and adds it to the specified section.
        /// </summary>
        /// <param name="section">INI section to add the key-value pair to.</param>
        /// <param name="line">Line of text.</param>
        /// <returns>INI key-value pair that was added to the section.</returns>
        private INIKeyValuePair AddKeyValuePairFromLine(INISection section, string line)
        {
            string key             = null;
            string value           = null;
            string comments        = null;
            int    whiteSpaceCount = 0;
            string lineMod         = line;

            if (lineMod.Contains(";"))
            {
                int index = lineMod.IndexOf(';');
                comments        = lineMod.Substring(index, line.Length - index);
                lineMod         = line.Replace(comments, "").Trim();
                whiteSpaceCount = line.Replace(lineMod, "").Replace(comments, "").Length;
                comments        = comments.ReplaceFirst(";", "");
            }

            if (line.Contains("="))
            {
                key   = lineMod.Substring(0, lineMod.IndexOf('=')).Trim();
                value = lineMod.Substring(lineMod.IndexOf('=') + 1, lineMod.Length - lineMod.IndexOf('=') - 1).Trim();
            }
            else
            {
                key = lineMod.Trim();
            }

            INIKeyValuePair kvp      = new INIKeyValuePair(key, value);
            INIKeyValuePair kvpMatch = section.KeyValuePairs.Find(x => x.Key == kvp.Key);

            if (kvpMatch == null)
            {
                section.KeyValuePairs.Add(kvp);
            }
            else
            {
                kvpMatch.Value = kvp.Value;
                kvp            = kvpMatch;
            }

            if (comments != null)
            {
                INIComment iniComment = new INIComment(comments, INICommentPosition.Middle, whiteSpaceCount);

                if (!kvp.HasComment(iniComment))
                {
                    kvp.AddComment(iniComment);
                }
            }

            return(kvp);
        }
Exemple #2
0
 /// <summary>
 /// Checks whether or not this key-value pair already contains a matching comment.
 /// </summary>
 /// <returns>True if key-value pair contains a matching comment, otherwise false.</returns>
 public bool HasComment(INIComment comment)
 {
     return(attachedComments.Find(x => x.CommentText == comment.CommentText && x.Position == comment.Position) != null);
 }
Exemple #3
0
 /// <summary>
 /// Adds a comment to this key-value pair.
 /// </summary>
 /// <param name="comment">Comment to add.</param>
 public void AddComment(INIComment comment)
 {
     attachedComments.Add(comment);
 }