Пример #1
0
 public void Set(KeyValuesData kvData)
 {
     if (!kvData.IsValid())
     {
         return;
     }
     kvData.Parent = this;
     KeyNameValues.Add(kvData);
 }
Пример #2
0
 public bool RemoveKeyName(KeyValuesData keyData)
 {
     if (KeyNameValues.Remove(keyData))
     {
         keyData.Parent = null;
         return(true);
     }
     return(false);
 }
Пример #3
0
        public void SetString(string keyName, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                value = "";
            }
            for (int i = 0; i < KeyNameValues.Count; i++)
            {
                if (KeyNameValues[i].Key == keyName)
                {
                    KeyNameValues[i].Value = value;
                    return;
                }
            }
            KeyValuesData kvValue = new KeyValuesData(keyName, value, null, this);

            KeyNameValues.Add(kvValue);
        }
Пример #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);
            }
            bool   wasQuoted   = false;
            bool   wasComment  = false;
            string lastComment = null;
            bool   wasName     = false;

            endPos = 0;
            for (uint i = startPos; i < stream.Count; i++)
            {
                KeyValuePair <string, string> 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 ? false : true);
                }
                // 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;
                    uint beganIndex = RetriveIndex(stream, "{", i + 1);
                    if (beganIndex == 0)
                    {
                        return(false);
                    }
                    i = beganIndex;
                    continue;
                }
                // Begin a new KeyValue Class
                if (kvPair.Key == "{")
                {
                    if (!wasQuoted)
                    {
                        lastComment = null;
                        KeyValues 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;
                }
                KeyValuesData kvData = new KeyValuesData(kvPair.Key, kvPair.Value, lastComment, this);
                KeyNameValues.Add(kvData);
                lastComment = null;
            }
            return(true);
        }
Пример #5
0
 public KeyValues(string setName, KeyValuesData keyValue)
     : this(setName)
 {
     Set(keyValue);
 }