Exemplo n.º 1
0
        public void AddValue(string section, string key, string value)
        {
            NormalizeKey(ref section);
            NormalizeKey(ref key);
            value = string.IsNullOrEmpty(value) ? string.Empty : value.Trim();

            var newLine = new TinyIniLine()
            {
                LineType = TinyIniLineType.KeyValue,
                Section  = section,
                Key      = key,
                Value    = value
            };

            IniLineSet.Add(newLine);
            IsChanged = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// zakladni parsovaci fce jednoho radku ini souboru
        /// </summary>
        /// <param name="line">zdrojovy radek</param>
        /// <param name="prevSection">posledni dohledana sekce ini</param>
        /// <returns>TinyIniLine</returns>
        private TinyIniLine ParseLine(string line, string prevSection)
        {
            var iniLine = new TinyIniLine()
            {
                Section    = prevSection,
                LineType   = TinyIniLineType.Other,
                SourceLine = line
            };

            if (!string.IsNullOrEmpty(line))
            {
                line = line.Trim();
                if (!string.IsNullOrEmpty(line))
                {
                    var firstChar = line.First();
                    if ((firstChar == '[') && (line.Last() == ']'))
                    {
                        // [] sekce
                        iniLine.LineType = TinyIniLineType.Section;
                        iniLine.Section  = line.Substring(1, line.Count() - 2);
                    }
                    else if (firstChar != ';')
                    {
                        // key=value
                        iniLine.LineType = TinyIniLineType.KeyValue;
                        iniLine.Section  = prevSection;
                        var eqIndex = line.IndexOf('=');
                        if (eqIndex < 0)
                        {
                            iniLine.Key = line;
                        }
                        else
                        {
                            iniLine.Key   = line.Substring(0, eqIndex);
                            iniLine.Value = line.Substring(eqIndex + 1);
                        }
                    }
                    else
                    {
                        iniLine.Section = prevSection;
                    }
                }
            }
            return(iniLine);
        }