Hyena.Query.QueryListNode.Trim C# (CSharp) Method

Trim() public method

public Trim ( ) : QueryNode
return QueryNode
        public override QueryNode Trim()
        {
            // Trim depth first
            List<QueryNode> copy = new List<QueryNode> (Children);
            foreach (QueryNode child in copy)
                child.Trim ();

            if (Keyword == Keyword.Not) {
                if (ChildCount != 1) {
                    if (Parent != null) {
                        Parent.RemoveChild (this);
                    } else {
                        return null;
                    }
                }
            } else {
                if (ChildCount <= 1) {
                    if (Parent != null) {
                        QueryListNode p = Parent;
                        p.RemoveChild (this);
                        p.TakeChildren (this);
                    } else if (ChildCount == 1) {
                        Children[0].Parent = null;
                        return Children[0];
                    }
                }
            }

            return this;
        }

Usage Example

示例#1
0
        public override QueryNode BuildTree (QueryFieldSet fieldSet)
        {
            field_set = fieldSet;
            root = current_parent = new QueryListNode (Keyword.And);
            bool last_was_term = false;

            while (true) {
                QueryToken token = Scan ();

                if (token.ID == TokenID.Unknown) {
                    break;
                }

                token.Column = token_start_column;
                token.Line = token_start_line;

                // If we have two terms in a row, put an AND between them
                if (last_was_term && token.ID == TokenID.Term)
                    ParseToken (new QueryToken (TokenID.And));

                ParseToken (token);

                last_was_term = token.ID == TokenID.Term;
            }

            return root.Trim ();
        }
All Usage Examples Of Hyena.Query.QueryListNode::Trim