Defines data for a Parser configuration object.
Inheritance: ICloneable
        public override bool Equals(object obj)
        {
            IniParserConfiguration iniParserConfiguration = obj as IniParserConfiguration;
            bool flag = iniParserConfiguration == null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                Type type = base.GetType();
                try
                {
                    foreach (PropertyInfo propertyInfo in type.GetProperties())
                    {
                        bool flag2 = propertyInfo.GetValue(iniParserConfiguration, null).Equals(propertyInfo.GetValue(this, null));
                        if (flag2)
                        {
                            return(false);
                        }
                    }
                }
                catch
                {
                    return(false);
                }
                result = true;
            }
            return(result);
        }
        public void check_default_values()
        {
            var config = new IniParserConfiguration();

            Assert.That(config, Is.Not.Null);
            Assert.That(config.CommentRegex, Is.Not.Null);
            Assert.That(config.SectionRegex, Is.Not.Null);
        }
Example #3
0
        /// <summary>
        ///     Ctor
        /// </summary>
        /// <param name="parserConfiguration">
        ///     Parser's <see cref="IniParserConfiguration"/> instance.
        /// </param>
        public IniDataParser(IniParserConfiguration parserConfiguration)
        {
            if (parserConfiguration == null)
                throw new ArgumentNullException("parserConfiguration");

            Configuration = parserConfiguration;

            _errorExceptions = new List<Exception>();
        }
 public IniParserConfiguration(IniParserConfiguration ori)
 {
     this.AllowDuplicateKeys       = ori.AllowDuplicateKeys;
     this.OverrideDuplicateKeys    = ori.OverrideDuplicateKeys;
     this.AllowDuplicateSections   = ori.AllowDuplicateSections;
     this.AllowKeysWithoutSection  = ori.AllowKeysWithoutSection;
     this.AllowCreateSectionsOnFly = ori.AllowCreateSectionsOnFly;
     this.SectionStartChar         = ori.SectionStartChar;
     this.SectionEndChar           = ori.SectionEndChar;
     this.CommentString            = ori.CommentString;
     this.ThrowExceptionsOnError   = ori.ThrowExceptionsOnError;
 }
Example #5
0
        /// <summary>
        ///     Copy ctor.
        /// </summary>
        /// <param name="ori">
        ///     Original instance to be copied.
        /// </param>
        public IniParserConfiguration(IniParserConfiguration ori)
        {
            AllowDuplicateKeys      = ori.AllowDuplicateKeys;
            OverrideDuplicateKeys   = ori.OverrideDuplicateKeys;
            AllowDuplicateSections  = ori.AllowDuplicateSections;
            AllowKeysWithoutSection = ori.AllowKeysWithoutSection;

            SectionStartChar       = ori.SectionStartChar;
            SectionEndChar         = ori.SectionEndChar;
            CommentString          = ori.CommentString;
            ThrowExceptionsOnError = ori.ThrowExceptionsOnError;

            // Regex values should recreate themselves.
        }
        public void parse_case_insensitive_names_ini_file()
        {
            string iniData = @"[TestSection]
            KEY1 = value1
            KEY2 = value2";

            var config = new IniParserConfiguration();
            config.CaseInsensitive = true;
            var data = new IniDataParser(config).Parse(iniData);

            Assert.That(data["testsection"]["key1"], Is.EqualTo("value1"));
            Assert.That(data["testSection"]["Key2"], Is.EqualTo("value2"));

        }
        /// <summary>
        ///     Copy ctor.
        /// </summary>
        /// <param name="ori">
        ///     Original instance to be copied.
        /// </param>
        public IniParserConfiguration(IniParserConfiguration ori)
        {
            AllowDuplicateKeys = ori.AllowDuplicateKeys;
            OverrideDuplicateKeys = ori.OverrideDuplicateKeys;
            AllowDuplicateSections = ori.AllowDuplicateSections;
            AllowKeysWithoutSection = ori.AllowKeysWithoutSection;

            SectionStartChar = ori.SectionStartChar;
            SectionEndChar = ori.SectionEndChar;
            CommentString = ori.CommentString;
            ThrowExceptionsOnError = ori.ThrowExceptionsOnError;

          // Regex values should recreate themselves.
        }
        public void check_cloning()
        {
            IniParserConfiguration config1 = new IniParserConfiguration();

            config1.AllowDuplicateKeys = true;
            config1.CommentString = "/";

			Assert.That(config1.AllowDuplicateKeys, Is.True);
			Assert.That(config1.CommentString, Is.EqualTo("/"));

			IniParserConfiguration config2 = config1.Clone();

            Assert.That(config2.AllowDuplicateKeys, Is.True);
            Assert.That(config2.CommentString, Is.EqualTo("/"));

            config1.CommentString = "#";
            Assert.That(config2.CommentString, Is.EqualTo("/"));
        }
Example #9
0
        public void simple_configuration()
        {
            var iniStr = @"[section1]
#data = 1
;data = 2";

            var config = new IniParserConfiguration();

            config.CommentString = "#";

            _parser = new IniDataParser(config);

            var iniData = _parser.Parse(iniStr);

            Assert.That(iniData["section1"][";data"], Is.EqualTo("2"));

        }
 public void SaveSettings(string fileName)
 {
     if (ParsedConfig == null)
         ParsedConfig = new IniData();
     // Note that this will persist the merged global & user configurations, not the original global config.
     // Since we don't call this method from production code, this is not an issue.
     // TODO: parserConfig is also created in ParseFiles. Consider making it a static member for consistency.
     var parserConfig = new IniParserConfiguration {
         // ThrowExceptionsOnError = false,
         CommentString = "#",
         SkipInvalidLines = true
     };
     var parser = new IniDataParser(parserConfig);
     var fileParser = new FileIniDataParser(parser);
     var utf8 = new UTF8Encoding(false);
     fileParser.WriteFile(fileName, ParsedConfig, utf8);
 }
        public static IniData ParseFiles(string defaultConfig, string globalConfigFilename)
        {
            var utf8 = new UTF8Encoding(false);
            var parserConfig = new IniParserConfiguration {
                // ThrowExceptionsOnError = false,
                CommentString = "#",
                SkipInvalidLines = true
            };

            var parser = new IniDataParser(parserConfig);
            IniData result = parser.Parse(DefaultLfMergeSettings.DefaultIniText);

            string globalIni = File.Exists(globalConfigFilename) ? File.ReadAllText(globalConfigFilename, utf8) : "";
            if (String.IsNullOrEmpty(globalIni))
            {
                // TODO: Make all these Console.WriteLine calls into proper logging calls
                Console.WriteLine("Warning: no global configuration found. Will use default settings.");
            }
            IniData globalConfig;
            try
            {
                globalConfig = parser.Parse(globalIni);
            }
            catch (ParsingException e)
            {
                Console.WriteLine("Warning: Error parsing global configuration file. Will use default settings.");
                Console.WriteLine("Error follows: {0}", e.ToString());
                globalConfig = null; // Merging null is perfectly acceptable to IniParser
            }
            result.Merge(globalConfig);

            foreach (KeyData item in result.Global)
            {
                // Special-case. Could be replaced with a more general regex if we end up using more variables, but YAGNI.
                if (item.Value.Contains("${HOME}"))
                {
                    item.Value = item.Value.Replace("${HOME}", Environment.GetEnvironmentVariable("HOME"));
                }
            }

            return result;
        }
 public DefaultIniDataFormatter(IniParserConfiguration configuration)
 {
     if (configuration == null)
         throw new ArgumentNullException("configuration");
     this.Configuration = configuration;
 }