/// <summary> /// Inserts the given combinator. /// </summary> /// <param name="cssCombinator">The combinator to insert.</param> void Insert(CssCombinator cssCombinator) { hasCombinator = true; if (cssCombinator != CssCombinator.Descendent) { combinator = cssCombinator; } }
/// <summary> /// Resets the current state. /// </summary> /// <returns>The current instance.</returns> public CssSelectorConstructor Reset() { attrName = null; attrValue = null; attrOp = String.Empty; state = State.Data; combinator = CssCombinator.Descendent; hasCombinator = false; temp = null; group = null; complex = null; return(this); }
/// <summary> /// Inserts the given selector. /// </summary> /// <param name="selector">The selector to insert.</param> void Insert(ISelector selector) { if (temp != null) { if (!hasCombinator) { var compound = temp as CompoundSelector; if (compound == null) { compound = new CompoundSelector(); compound.Add(temp); } compound.Add(selector); temp = compound; } else { if (complex == null) { complex = new ComplexSelector(); } complex.AppendSelector(temp, combinator); combinator = CssCombinator.Descendent; hasCombinator = false; temp = selector; } } else { combinator = CssCombinator.Descendent; hasCombinator = false; temp = selector; } }
public void AppendSelector(ISelector selector, CssCombinator combinator) { if (!IsReady) { _selectors.Add(new CombinatorSelector { Selector = combinator.Change(selector), Transform = combinator.Transform, Delimiter = combinator.Delimiter }); } }
/// <summary> /// Inserts the given combinator. /// </summary> /// <param name="cssCombinator">The combinator to insert.</param> void Insert(CssCombinator cssCombinator) { combinators.Push(cssCombinator); }
/// <summary> /// Appends a selector to the complex of selectors. /// </summary> /// <param name="selector">The selector to append.</param> /// <param name="combinator">The combinator to use.</param> /// <returns>The current complex selector.</returns> public ComplexSelector AppendSelector(ISelector selector, CssCombinator combinator) { if (IsReady) return this; selectors.Add(new CombinatorSelector { Selector = combinator.Change(selector), Transform = combinator.Transform, Delimiter = combinator.Delimiter }); return this; }
/// <summary> /// Appends a selector to the complex of selectors. /// </summary> /// <param name="selector">The selector to append.</param> /// <param name="combinator">The combinator to use.</param> /// <returns>The current complex selector.</returns> public ComplexSelector AppendSelector(ISelector selector, CssCombinator combinator) { if (IsReady) return this; Func<IElement, IEnumerable<IElement>> transform = null; char delim; switch (combinator) { case CssCombinator.Child: { delim = Specification.GreaterThan; transform = el => Single(el.ParentElement); break; } case CssCombinator.AdjacentSibling: { delim = Specification.Plus; transform = el => Single(el.PreviousElementSibling); break; } case CssCombinator.Descendent: { delim = Specification.Space; transform = el => { var parents = new List<IElement>(); var parent = el.ParentElement; while (parent != null) { parents.Add(parent); parent = parent.ParentElement; } return parents; }; break; } case CssCombinator.Sibling: { delim = Specification.Tilde; transform = el => { var parent = el.ParentElement; if (parent == null) return new IElement[0]; var kids = parent.Children; var siblings = new List<IElement>(); foreach (var kid in kids) { if (kid == el) break; siblings.Add(kid); } //var passed = false; //for (int i = kids.Length - 1; i >= 0; i--) //{ // if (kids[i] == el) // passed = true; // else if (passed) // siblings.Add(kids[i]); //} return siblings; }; break; } default: return this; } selectors.Add(new CombinatorSelector { selector = selector, transform = transform, delimiter = delim }); return this; }