Пример #1
0
        /// <summary>
        /// Find an IniEnt with specified name and remove it from file, return a NullEntity(not null) if not found
        /// </summary>
        /// <param name="entName"></param>
        /// <returns></returns>
        public INIEntity PopEnt(string entName)
        {
            INIEntity result = GetEnt(entName);

            RemoveEnt(result);
            return(result);
        }
Пример #2
0
 /// <summary>
 /// Remove an IniEnt with a specified name, will do nothing if not found
 /// </summary>
 /// <param name="ent"></param>
 public void RemoveEnt(INIEntity ent)
 {
     if (inidata.Keys.Contains(ent.Name))
     {
         inidata.Remove(ent.Name);
     }
 }
Пример #3
0
 /// <summary>
 /// Add an IniEnt, if there is an IniEnt with same name, it will do nothing
 /// </summary>
 /// <param name="ent"></param>
 public void AddEnt(INIEntity ent)
 {
     if (string.IsNullOrEmpty(ent.Name))
     {
         return;
     }
     if (!inidata.Keys.Contains(ent.Name))
     {
         inidata[ent.Name] = ent;
     }
 }
Пример #4
0
 /// <summary>
 /// Merge two IniEnt, items with same key will be overwrite by new one.
 /// </summary>
 /// <param name="newEnt">New Ent</param>
 public void JoinWith(INIEntity newEnt)
 {
     if (entitytype == INIEntType.ListType)
     {
         int maxindex = Reorganize();
         foreach (INIPair p in newEnt)
         {
             p.Name       = maxindex++.ToString();
             data[p.Name] = p;
         }
     }
     else
     {
         foreach (INIPair p in newEnt)
         {
             data[p.Name] = p;
         }
     }
 }
Пример #5
0
        private void Load()
        {
            bool      init             = true;
            string    preCommentBuffer = "";
            INIEntity ent      = new INIEntity();
            string    rootname = "";
            string    rootcom  = "";

            while (CanRead())
            {
                string line   = Readline();
                string combuf = "";
                if (line.Contains(";"))
                {
                    string[] ls = line.Split(new char[] { ';' }, 2);
                    if (ls[0] == "")
                    {
                        preCommentBuffer += ";" + ls[1] + "\n";
                        continue;
                    }
                    else
                    {
                        combuf = ls[1];
                    }
                    line = ls[0];
                }
                line = line.Replace("\t", string.Empty).Replace("\r\n", string.Empty).Replace("\r", string.Empty);
                line = line.Trim();
                if (line == "")
                {
                    continue;
                }
                if (line.StartsWith("["))
                {
                    if (init)
                    {
                        init             = false;
                        rootname         = line.Replace("[", string.Empty).Replace("]", string.Empty);
                        ent              = new INIEntity(rootname, preCommentBuffer, combuf);
                        preCommentBuffer = "";
                        continue;
                    }
                    AddEnt(ent);
                    rootname = line.Replace("[", string.Empty).Replace("]", string.Empty);
                    ent      = new INIEntity(rootname, preCommentBuffer, combuf);
                    rootcom  = combuf;
                }
                else if (line.StartsWith("*"))
                {
                    continue;
                }
                else
                {
                    INIPair  p;
                    string[] tmp = line.Split(new char[] { '=' }, 2);
                    if (tmp.Length == 1)
                    {
                        p = new INIPair(tmp[0].Trim(), "", combuf, preCommentBuffer);
                    }
                    else
                    {
                        p = new INIPair(tmp[0].Trim(), tmp[1].Trim(), combuf, preCommentBuffer);
                    }
                    ent.AddPair(p);
                    preCommentBuffer = "";
                }
            }
            AddEnt(ent);
        }
Пример #6
0
 /// <summary>
 /// Only check the name
 /// </summary>
 /// <param name="ent"></param>
 /// <returns></returns>
 public bool HasIniEnt(INIEntity ent)
 {
     return(inidata.Keys.Contains(ent.Name));
 }