File indexing completed on 2024-04-14 05:44:25

0001 /*
0002  *  SPDX-FileCopyrightText: 2002-2004 Jesper K. Pedersen <blackie@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-only
0005  **/
0006 
0007 #ifndef REGEXPCONVERTER_H
0008 #define REGEXPCONVERTER_H
0009 
0010 #include <QList>
0011 
0012 class QTextEdit;
0013 class AltnRegExp;
0014 class ConcRegExp;
0015 class LookAheadRegExp;
0016 class TextRangeRegExp;
0017 class CompoundRegExp;
0018 class DotRegExp;
0019 class PositionRegExp;
0020 class RepeatRegExp;
0021 class TextRegExp;
0022 class RegexpHighlighter;
0023 class RegExp;
0024 class QChar;
0025 
0026 class RegExpConverter
0027 {
0028 public:
0029     enum Features {
0030         WordBoundary = 0x01,
0031         NonWordBoundary = 0x02,
0032         WordStart = 0x04,
0033         WordEnd = 0x08,
0034         PosLookAhead = 0x10,
0035         NegLookAhead = 0x20,
0036         CharacterRangeNonItems = 0x40,
0037         ExtRange = 0x80
0038     };
0039     virtual ~RegExpConverter()
0040     {
0041     }
0042 
0043     virtual bool canParse() = 0;
0044     virtual QString name() = 0;
0045     virtual int features() = 0;
0046     virtual RegExp *parse(const QString &, bool *ok);
0047     QString toStr(RegExp *, bool markSelection);
0048     virtual RegexpHighlighter *highlighter(QTextEdit *);
0049 
0050     static void setCurrent(RegExpConverter *);
0051     static RegExpConverter *current();
0052 
0053 protected:
0054     virtual QString toString(AltnRegExp *, bool markSelection) = 0;
0055     virtual QString toString(ConcRegExp *, bool markSelection) = 0;
0056     virtual QString toString(LookAheadRegExp *, bool markSelection) = 0;
0057     virtual QString toString(TextRangeRegExp *, bool markSelection) = 0;
0058     virtual QString toString(CompoundRegExp *, bool markSelection) = 0;
0059     virtual QString toString(DotRegExp *, bool markSelection) = 0;
0060     virtual QString toString(PositionRegExp *, bool markSelection) = 0;
0061     virtual QString toString(RepeatRegExp *, bool markSelection) = 0;
0062     virtual QString toString(TextRegExp *, bool markSelection) = 0;
0063     QString escape(const QString &text, const QList<QChar> &chars, QChar escapeChar) const;
0064 
0065 private:
0066     static RegExpConverter *_current;
0067 };
0068 
0069 #endif /* REGEXPCONVERTER_H */