Пример #1
0
        public SimpleSelector(string selector)
        {
            if(selector == null)
                throw new ArgumentNullException("selector");

            _attributeSelectors = new List<AttributeSelector>();

            int length = selector.Length;
            int position = 0;

            while (position < length)
            {
                int i = selector.IndexOf('[', position);
                if (i < 0)
                {
                    if(_elementName == null)
                        _elementName = selector.Substring(position);
                    position = length;
                }
                else
                {
                    if (_elementName == null)
                        _elementName = selector.Substring(position, i);

                    int j = selector.IndexOf(']', i);
                    if (j < 0)
                    {
                        position = length;
                    }
                    else
                    {
                        AttributeSelector attributeSelector = new AttributeSelector(selector.Substring(i + 1, j - i - 1));
                        _attributeSelectors.Add(attributeSelector);
                        position = j + 1;
                    }
                }
            }

            if (_elementName == "*")
                _elementName = string.Empty;
        }