Beispiel #1
0
 public void Set(KeyValuesData kvData)
 {
     if (!kvData.IsValid())
     {
         return;
     }
     kvData.Parent = this;
     KeyNameValues.Add(kvData);
 }
Beispiel #2
0
 public bool RemoveKeyName(KeyValuesData keyData)
 {
     if (KeyNameValues.Remove(keyData))
     {
         keyData.Parent = null;
         return(true);
     }
     return(false);
 }
Beispiel #3
0
        public void SetString(string keyName, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                value = "";
            }
            foreach (var t in KeyNameValues)
            {
                if (t.Key != keyName)
                {
                    continue;
                }
                t.Value = value;
                return;
            }
            var kvValue = new KeyValuesData(keyName, value, null, this);

            KeyNameValues.Add(kvValue);
        }
Beispiel #4
0
        /// <summary>
        ///     Create a KeyValue from List wich contains file lines
        /// </summary>
        /// <returns>
        ///     true if the sucessfully load (KeyValue is valid); otherwise, false.
        /// </returns>
        /// <param name="stream">List collection wich contain file lines</param>
        /// <param name="startPos">Start parse List in that position</param>
        /// <param name="endPos">Return end position index</param>
        private bool LoadFromList(List <string> stream, uint startPos, ref uint endPos)
        {
            if (stream == null)
            {
                return(false);
            }
            var    wasQuoted   = false;
            var    wasComment  = false;
            string lastComment = null;
            var    wasName     = false;

            endPos = 0;
            for (var i = startPos; i < stream.Count; i++)
            {
                var kvPair = ReadToken(stream[(int)i], ref wasQuoted, ref wasComment);
                if (string.IsNullOrEmpty(kvPair.Key))
                {
                    continue;
                }
                endPos = i;
                // Is the end of KeyValues Class?
                if (kvPair.Key == "}")
                {
                    endPos = i + 1;
                    return(Name != null);
                }
                // This line is a comment
                if (wasComment)
                {
                    lastComment = kvPair.Value;
                    continue;
                }
                // KeyValue Name not yet seted!
                if (!wasName)
                {
                    if (!string.IsNullOrEmpty(kvPair.Value))
                    {
                        return(false);
                    }
                    Name = kvPair.Key;
                    if (!string.IsNullOrEmpty(lastComment))
                    {
                        Comment = lastComment;
                    }
                    wasName     = true;
                    lastComment = null;
                    var beganIndex = RetriveIndex(stream, "{", i + 1);
                    if (beganIndex == 0)
                    {
                        return(false);
                    }
                    i = beganIndex;
                    continue;
                }
                // special include macro (not a key name)
                if (kvPair.Key.StartsWith("#include") && !wasQuoted)
                {
                    lastComment = null;
                    if (string.IsNullOrEmpty(kvPair.Value))
                    {
                        continue;
                    }
                    AddIncludeFile(kvPair.Value, true, true);
                    continue;
                }
                // Begin a new KeyValue Class
                if (kvPair.Key == "{")
                {
                    if (!wasQuoted)
                    {
                        lastComment = null;
                        var kvChild = new KeyValues("NewName");
                        if (!kvChild.LoadFromList(stream, i - 1, ref endPos))
                        {
                            continue;
                        }
                        Update(kvChild, true);
                        KeyChilds.Add(kvChild);
                        if (endPos >= stream.Count)
                        {
                            return(true);
                        }
                        i = endPos;
                        continue;
                    }
                }
                // Is a KeyValue    "Key"       "Value"
                if (string.IsNullOrEmpty(kvPair.Value))
                {
                    continue;
                }
                var kvData = new KeyValuesData(kvPair.Key, kvPair.Value, lastComment, this);
                KeyNameValues.Add(kvData);
                lastComment = null;
            }
            return(true);
        }
Beispiel #5
0
 public KeyValues(string setName, KeyValuesData keyValue)
     : this(setName)
 {
     Set(keyValue);
 }