File indexing completed on 2024-04-21 05:51:37

0001 /*
0002  *  SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-only
0005  **/
0006 
0007 #include "lookaheadregexp.h"
0008 #include "errormap.h"
0009 
0010 LookAheadRegExp::LookAheadRegExp(bool selected, TYPE tp, RegExp *child)
0011     : RegExp(selected)
0012     , _child(child)
0013     , _tp(tp)
0014 {
0015     if (child) {
0016         addChild(child);
0017     }
0018 }
0019 
0020 bool LookAheadRegExp::check(ErrorMap &map, bool, bool last)
0021 {
0022     if (!last) {
0023         map.lookAheadError();
0024     }
0025     return true;
0026 }
0027 
0028 QDomNode LookAheadRegExp::toXml(QDomDocument *doc) const
0029 {
0030     QDomElement top;
0031     if (_tp == POSITIVE) {
0032         top = doc->createElement(QStringLiteral("PositiveLookAhead"));
0033     } else {
0034         top = doc->createElement(QStringLiteral("NegativeLookAhead"));
0035     }
0036 
0037     top.appendChild(_child->toXml(doc));
0038     return top;
0039 }
0040 
0041 bool LookAheadRegExp::load(const QDomElement &top, const QString &version)
0042 {
0043     _child = readRegExp(top, version);
0044     if (_child) {
0045         addChild(_child);
0046         return true;
0047     } else {
0048         return false;
0049     }
0050 }
0051 
0052 bool LookAheadRegExp::operator==(const RegExp &other) const
0053 {
0054     if (type() != other.type()) {
0055         return false;
0056     }
0057 
0058     const LookAheadRegExp &theOther = dynamic_cast<const LookAheadRegExp &>(other);
0059 
0060     if (lookAheadType() != theOther.lookAheadType()) {
0061         return false;
0062     }
0063 
0064     return *_child == *(theOther._child);
0065 }