///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="index"></param> /// <param name="property"></param> /// <returns></returns> public int Insert(int index, DCssProperty property) { System.Diagnostics.Debug.Assert(index >= 0 && index <= m_propertyList.Count); System.Diagnostics.Debug.Assert(property != null); object result = m_propertyHash[property.Name]; if (result == null) // Find the property name whether the it exists in collection. { result = index; m_propertyHash[property.Name] = index; m_propertyList.Insert(index, property); // Update index of m_propertyHash after "index" for (int scan = index + 1, count = m_propertyList.Count; scan < count; ++scan) { string name = m_propertyList[scan].Name; m_propertyHash[name] = (int)m_propertyHash[name] + 1; } } else { m_propertyList[(int)result] = property; } return((int)result); }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="property"></param> /// <returns></returns> public int AddFirst(DCssProperty property) { System.Diagnostics.Debug.Assert(property != null); object result = m_propertyHash[property.Name]; if (result == null) // Find the property name whether the it exists in collection. { result = 0; m_propertyHash[property.Name] = 0; m_propertyList.Insert(0, property); // Update index of m_propertyHash after 0. for (int index = 1, count = m_propertyList.Count; index < count; ++index) { string name = m_propertyList[index].Name; m_propertyHash[name] = (int)m_propertyHash[name] + 1; } } else { m_propertyList[(int)result] = property; } return((int)result); }
/////////////////////////////////////////////////////////////////////////////// /// <summary> /// »ý¼ºÀÚ /// </summary> public DCssProperty(DCssProperty obj) { System.Diagnostics.Debug.Assert(obj != null); obj.AssertValid(); m_propertyName = obj.m_propertyName; m_propertyValue = obj.m_propertyValue; }
/////////////////////////////////////////////////////////////////////////////// /// <summary> /// ������ /// </summary> public DCssProperty(DCssProperty obj) { System.Diagnostics.Debug.Assert(obj != null); obj.AssertValid(); m_propertyName = obj.m_propertyName; m_propertyValue = obj.m_propertyValue; }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="index"></param> public void RemoveAt(int index) { System.Diagnostics.Debug.Assert(index >= 0 && index < m_propertyList.Count); DCssProperty property = m_propertyList[index]; // Update index of m_propertyHash after "index" for (int scan = index + 1, count = m_propertyList.Count; scan < count; ++scan) { string name = m_propertyList[scan].Name; m_propertyHash[name] = (int)m_propertyHash[name] - 1; } m_propertyList.RemoveAt(index); m_propertyHash.Remove(property.Name); }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// This overload allows you to have direct access to an property by providing /// its name. If the property does not exist, null is returned. /// </summary> public DCssProperty this[string name] { get { System.Diagnostics.Debug.Assert(name != null); name = name.ToLower(); DCssProperty result = null; object index = m_propertyHash[name]; if (index != null) { result = m_propertyList[(int)index]; } return(result); } }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="property"></param> /// <returns></returns> public int AddLast(DCssProperty property) { System.Diagnostics.Debug.Assert(property != null); object result = m_propertyHash[property.Name]; if (result == null) // Find the property name whether the it exists in collection. { result = m_propertyList.Count; m_propertyHash[property.Name] = m_propertyList.Count; m_propertyList.Add(property); } else { m_propertyList[(int)result] = property; } return((int)result); }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="index"></param> public bool Remove(string name) { System.Diagnostics.Debug.Assert(name != null); object index = m_propertyHash[name]; if (index != null) { DCssProperty property = m_propertyList[(int)index]; // Update index of m_propertyHash after "index" for (int scan = (int)index + 1, count = m_propertyList.Count; scan < count; ++scan) { string scanName = m_propertyList[scan].Name; m_propertyHash[scanName] = (int)m_propertyHash[scanName] - 1; } m_propertyList.RemoveAt((int)index); m_propertyHash.Remove(property.Name); } return(index != null); }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="index"></param> /// <param name="property"></param> /// <returns></returns> public int Insert(int index, DCssProperty property) { System.Diagnostics.Debug.Assert(index >= 0 && index <= m_propertyList.Count); System.Diagnostics.Debug.Assert(property != null); object result = m_propertyHash[property.Name]; if(result == null) // Find the property name whether the it exists in collection. { result = index; m_propertyHash[property.Name] = index; m_propertyList.Insert(index, property); // Update index of m_propertyHash after "index" for(int scan = index + 1, count = m_propertyList.Count; scan < count; ++scan) { string name = m_propertyList[scan].Name; m_propertyHash[name] = (int)m_propertyHash[name] + 1; } } else m_propertyList[(int)result] = property; return (int)result; }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// This is used to identify the index of this node as it appears in the collection. /// </summary> /// <param name="node">The property to test</param> /// <returns>The index of the property, or -1 if it is not in this collection</returns> public int IndexOf(DCssProperty property) { System.Diagnostics.Debug.Assert(property != null); return m_propertyList.IndexOf(property); }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="property"></param> /// <returns></returns> public int AddLast(DCssProperty property) { System.Diagnostics.Debug.Assert(property != null); object result = m_propertyHash[property.Name]; if(result == null) // Find the property name whether the it exists in collection. { result = m_propertyList.Count; m_propertyHash[property.Name] = m_propertyList.Count; m_propertyList.Add(property); } else m_propertyList[(int)result] = property; return (int)result; }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="property"></param> /// <returns></returns> public int AddFirst(DCssProperty property) { System.Diagnostics.Debug.Assert(property != null); object result = m_propertyHash[property.Name]; if(result == null) // Find the property name whether the it exists in collection. { result = 0; m_propertyHash[property.Name] = 0; m_propertyList.Insert(0, property); // Update index of m_propertyHash after 0. for(int index = 1, count = m_propertyList.Count; index < count; ++index) { string name = m_propertyList[index].Name; m_propertyHash[name] = (int)m_propertyHash[name] + 1; } } else m_propertyList[(int)result] = property; return (int)result; }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public void ResolvePropertyList(string input, DCssPropertyCollection result) { System.Diagnostics.Debug.Assert(input != null); System.Diagnostics.Debug.Assert(result != null); PropertyListTokenType type = PropertyListTokenType.Name; int index = 0; string name = "", value = ""; while (index < input.Length) // PropertyList: S* declaration? [ ';' S* declaration? ]*; { // declaration: DELIM? property S* ':' S* value; int startIndex = 0; if (type == PropertyListTokenType.Name) { startIndex = input.IndexOfAny(":=".ToCharArray(), index); } else if (type == PropertyListTokenType.Value) { startIndex = input.IndexOf(';', index); } if (type == PropertyListTokenType.Name && startIndex != -1 && startIndex - index > 0 && (input[startIndex].Equals(':') || input[startIndex].Equals('='))) { name = input.Substring(index, startIndex - index); name = name.Trim(CHtmlUtil.WhiteSpaceCharsArray); if (name.Length > 0 && CHtmlUtil.ExistWhiteSpaceChar(name) == false) { type = PropertyListTokenType.Value; } } else if (type == PropertyListTokenType.Value && startIndex != -1 && startIndex - index > 0 && input[startIndex].Equals(';')) { value = input.Substring(index, startIndex - index); value = value.Trim(CHtmlUtil.WhiteSpaceCharsArray); if (value.Length > 0) { DCssProperty property = new DCssProperty(name, value); result.AddLast(property); } type = PropertyListTokenType.Name; } else if (type == PropertyListTokenType.Value && startIndex == -1) { value = input.Substring(index); value = value.Trim(CHtmlUtil.WhiteSpaceCharsArray); if (value.Length > 0) { DCssProperty property = new DCssProperty(name, value); result.AddLast(property); } type = PropertyListTokenType.Name; } else { type = PropertyListTokenType.Name; } if (startIndex == -1) { index = input.Length; } else { index = startIndex + 1; } } }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public void ResolvePropertyList(string input, DCssPropertyCollection result) { System.Diagnostics.Debug.Assert(input != null); System.Diagnostics.Debug.Assert(result != null); PropertyListTokenType type = PropertyListTokenType.Name; int index = 0; string name = "", value = ""; while(index < input.Length) // PropertyList: S* declaration? [ ';' S* declaration? ]*; { // declaration: DELIM? property S* ':' S* value; int startIndex = 0; if(type == PropertyListTokenType.Name) startIndex = input.IndexOfAny(":=".ToCharArray(), index); else if(type == PropertyListTokenType.Value) startIndex = input.IndexOf(';', index); if(type == PropertyListTokenType.Name && startIndex != -1 && startIndex - index > 0 && (input[startIndex].Equals(':') || input[startIndex].Equals('='))) { name = input.Substring(index, startIndex - index); name = name.Trim(CHtmlUtil.WhiteSpaceCharsArray); if(name.Length > 0 && CHtmlUtil.ExistWhiteSpaceChar(name) == false) type = PropertyListTokenType.Value; } else if(type == PropertyListTokenType.Value && startIndex != -1 && startIndex - index > 0 && input[startIndex].Equals(';')) { value = input.Substring(index, startIndex - index); value = value.Trim(CHtmlUtil.WhiteSpaceCharsArray); if(value.Length > 0) { DCssProperty property = new DCssProperty(name, value); result.AddLast(property); } type = PropertyListTokenType.Name; } else if(type == PropertyListTokenType.Value && startIndex == -1) { value = input.Substring(index); value = value.Trim(CHtmlUtil.WhiteSpaceCharsArray); if(value.Length > 0) { DCssProperty property = new DCssProperty(name, value); result.AddLast(property); } type = PropertyListTokenType.Name; } else type = PropertyListTokenType.Name; if(startIndex == -1) index = input.Length; else index = startIndex + 1; } }
///////////////////////////////////////////////////////////////////////////////// /// <summary> /// This is used to identify the index of this node as it appears in the collection. /// </summary> /// <param name="node">The property to test</param> /// <returns>The index of the property, or -1 if it is not in this collection</returns> public int IndexOf(DCssProperty property) { System.Diagnostics.Debug.Assert(property != null); return(m_propertyList.IndexOf(property)); }