Exemplo n.º 1
0
        public static IniElement ParseLine(string line)
        {
            if (line == null)
            {
                return(null);
            }
            if (line.Contains("\n"))
            {
                throw new ArgumentException("String passed to the ParseLine method cannot contain more than one line.");
            }
            var        trim = line.Trim();
            IniElement elem = null;

            if (IniBlankLine.IsLineValid(trim))
            {
                elem = new IniBlankLine(1);
            }
            else if (IniCommentary.IsLineValid(line))
            {
                elem = new IniCommentary(line);
            }
            else if (IniSectionStart.IsLineValid(trim))
            {
                elem = new IniSectionStart(line);
            }
            else if (IniValue.IsLineValid(trim))
            {
                elem = new IniValue(line);
            }
            return(elem ?? new IniElement(line));
        }
Exemplo n.º 2
0
        public static IniValue FromData(string key, string value)
        {
            var ret = new IniValue();

            ret._key   = key;
            ret._value = value;
            ret.FormatDefault();
            return(ret);
        }
Exemplo n.º 3
0
        private void SetValue(string key, string value)
        {
            IniValue ret  = null;
            IniValue prev = LastValue();

            if (IniSettings.PreserveFormatting)
            {
                if (prev != null && prev.Indentation.Length >= SectionStart.Indentation.Length)
                {
                    ret = prev.CreateNew(key, value);
                }
                else
                {
                    IniElement el;
                    var        valFound = false;
                    for (var i = Parent.Elements.IndexOf(SectionStart) - 1; i >= 0; i--)
                    {
                        el = Parent.Elements[i];
                        if (el is IniValue)
                        {
                            ret      = ((IniValue)el).CreateNew(key, value);
                            valFound = true;
                            break;
                        }
                    }
                    if (!valFound)
                    {
                        ret = IniValue.FromData(key, value);
                    }
                    if (ret.Indentation.Length < SectionStart.Indentation.Length)
                    {
                        ret.Indentation = SectionStart.Indentation;
                    }
                }
            }
            else
            {
                ret = IniValue.FromData(key, value);
            }
            if (prev == null)
            {
                Elements.Insert(Elements.IndexOf(SectionStart) + 1, ret);
                Parent.Elements.Insert(Parent.Elements.IndexOf(SectionStart) + 1, ret);
            }
            else
            {
                Elements.Insert(Elements.IndexOf(prev) + 1, ret);
                Parent.Elements.Insert(Parent.Elements.IndexOf(prev) + 1, ret);
            }
        }
Exemplo n.º 4
0
		public static IniElement ParseLine(string line)
		{
			if (line == null)
				return null;
			if (line.Contains("\n"))
				throw new ArgumentException("String passed to the ParseLine method cannot contain more than one line.");
			var trim = line.Trim();
			IniElement elem = null;
			if (IniBlankLine.IsLineValid(trim))
				elem = new IniBlankLine(1);
			else if (IniCommentary.IsLineValid(line))
				elem = new IniCommentary(line);
			else if (IniSectionStart.IsLineValid(trim))
				elem = new IniSectionStart(line);
			else if (IniValue.IsLineValid(trim))
				elem = new IniValue(line);
			return elem ?? new IniElement(line);
		}
Exemplo n.º 5
0
        public IniValue CreateNew(string key, string value)
        {
            var ret = new IniValue();

            ret._key   = key;
            ret._value = value;
            if (IniSettings.PreserveFormatting)
            {
                ret.formatting = formatting;
                if (IniSettings.AllowInlineComments)
                {
                    ret._inlineCommentChar = _inlineCommentChar;
                }
                ret.Format();
            }
            else
            {
                ret.FormatDefault();
            }
            return(ret);
        }
Exemplo n.º 6
0
 public IniValue GotoValue(string key, bool searchWholeFile)
 {
     while (true)
     {
         var str = ReadLine();
         if (str == null)
         {
             return(null);
         }
         if (IniValue.IsLineValid(str.Trim()))
         {
             var val = ParseLine(str) as IniValue;
             if (val != null &&
                 (val.Key == key || (!IniSettings.CaseSensitive && val.Key.ToLowerInvariant() == key.ToLowerInvariant())))
             {
                 return(val);
             }
         }
         if (!searchWholeFile && IniSectionStart.IsLineValid(str.Trim()))
         {
             return(null);
         }
     }
 }
Exemplo n.º 7
0
		public static IniValue FromData(string key, string value)
		{
			var ret = new IniValue();
			ret._key = key;
			ret._value = value;
			ret.FormatDefault();
			return ret;
		}
Exemplo n.º 8
0
		public IniValue CreateNew(string key, string value)
		{
			var ret = new IniValue();
			ret._key = key;
			ret._value = value;
			if (IniSettings.PreserveFormatting)
			{
				ret.formatting = formatting;
				if (IniSettings.AllowInlineComments)
					ret._inlineCommentChar = _inlineCommentChar;
				ret.Format();
			}
			else
				ret.FormatDefault();
			return ret;
		}