Exemplo n.º 1
0
            void IIniFileContentLineHandler.HandleSectionDeclaration(IniFileSectionDeclarationLine sectionLine)
            {
                var sectionName = sectionLine.SectionName;

                if (!_owner._sections.TryGetValue(sectionName, out _currSection))
                {
                    _currSection = new IniFileSectionData(sectionName);
                    _owner._sections.Add(sectionName, _currSection);
                }
            }
Exemplo n.º 2
0
        public static bool TryParse(string line, out IniFileLine record)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                record = IniFileNoMeaningContentLine.EmptyLine;
            }
            else
            {
                var match = Regex.Match(line, @"^((\[(?<sectionName>[^\]]*)\])|((?<key>[^=]*)=(?<value>[^\;]*)))(\;(?<commentText>[^\n]*))?$");
                if (match.Success)
                {
                    var sectionNameGroup = match.Groups["sectionName"];
                    var keyGroup         = match.Groups["key"];
                    var valueGroup       = match.Groups["value"];
                    var commentTextGroup = match.Groups["commentText"];

                    var commentText = commentTextGroup.Success ? commentTextGroup.Value : null;
                    if (sectionNameGroup.Success)
                    {
                        record = new IniFileSectionDeclarationLine(sectionNameGroup.Value.Trim(), commentText);
                    }
                    else if (keyGroup.Success && valueGroup.Success)
                    {
                        record = new IniFileKeyValueLine(keyGroup.Value.Trim(), valueGroup.Value.Trim(), commentText);
                    }
                    else
                    {
                        record = null;
                    }
                }
                else
                {
                    record = null;
                }
            }

            return(record != null);
        }