edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
regexp.h
Go to the documentation of this file.
1// edbee - Copyright (c) 2012-2025 by Rick Blommers and contributors
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "edbee/exports.h"
7
8#include <QString>
9
10namespace edbee {
11
15public:
16 virtual ~RegExpEngine() {}
17 virtual QString pattern() = 0;
18 virtual bool isValid() = 0;
19 virtual QString error() = 0;
20 virtual int indexIn( const QString& str, int offset ) = 0;
21 virtual int indexIn( const QChar* str, int offset, int length ) = 0;
22 virtual int lastIndexIn( const QString& str, int offset ) = 0;
23 virtual int lastIndexIn( const QChar* str, int offset, int length ) = 0;
24
25 virtual int pos( int nth = 0 ) const = 0;
26 virtual int len( int nth = 0 ) const = 0;
27 virtual QString cap( int nth = 0 ) const = 0;
28};
29
30
31
36public:
37 enum Engine {
40// QRegExp::RegExp 0 A rich Perl-like pattern matching syntax. This is the default.
41// QRegExp::RegExp2 3 Like RegExp, but with greedy quantifiers. (Introduced in Qt 4.2.)
42// QRegExp::Wildcard 1 This provides a simple pattern matching syntax similar to that used by shells (command interpreters) for "file globbing". See QRegExp wildcard matching.
43// QRegExp::WildcardUnix 4 This is similar to Wildcard but with the behavior of a Unix shell. The wildcard characters can be escaped with the character "\".
44// QRegExp::FixedString 2 The pattern is a fixed string. This is equivalent to using the RegExp pattern on a string in which all metacharacters are escaped using escape().
45// QRegExp::W3CXmlSchema11 5 The pattern is a regular expression as defined by the W3C XML Schema 1.1 specification.
46 };
47
52
53
54
55 RegExp( const QString& pattern, bool caseSensitive=true, Syntax syntax=SyntaxDefault, Engine engine=EngineOniguruma );
56 virtual ~RegExp();
57
58 static QString escape( const QString& str, Engine engine=EngineOniguruma );
59
60 bool isValid() const;
61 QString errorString() const ;
62 QString pattern() const ;
63
64
65 int indexIn( const QString& str, int offset = 0 ); // const;
66 int indexIn( const QChar* str, int offset, int length );
67 int lastIndexIn( const QString& str, int offset=-1 );
68 int lastIndexIn( const QChar* str, int offset, int length );
69 int pos( int nth = 0 ) const;
70 int len( int nth = 0 ) const;
71 QString cap( int nth = 0) const;
72
73
75 int matchedLength() { return len(0); }
76
77 // int cap( int nth = 0 ) const;
78
79private:
80 RegExpEngine* d_;
81};
82
83} // edbee
The minimal engine we currently require for handling regexpt. It may grow in the future.
Definition regexp.h:14
virtual ~RegExpEngine()
Definition regexp.h:16
virtual QString cap(int nth=0) const =0
virtual int pos(int nth=0) const =0
virtual int indexIn(const QString &str, int offset)=0
virtual int indexIn(const QChar *str, int offset, int length)=0
virtual int len(int nth=0) const =0
virtual int lastIndexIn(const QString &str, int offset)=0
virtual int lastIndexIn(const QChar *str, int offset, int length)=0
virtual bool isValid()=0
virtual QString error()=0
virtual QString pattern()=0
A class for matching QStrings with the Oniguruma API We need this Regular Expression library to be ab...
Definition regexp.h:35
int matchedLength()
matched length is equal to pos-0-length
Definition regexp.h:75
RegExp(const QString &pattern, bool caseSensitive=true, Syntax syntax=SyntaxDefault, Engine engine=EngineOniguruma)
Constructs the regular expression matcher.
Definition regexp.cpp:391
int len(int nth=0) const
The length of nth element.
Definition regexp.cpp:499
Engine
Definition regexp.h:37
@ EngineOniguruma
Definition regexp.h:38
@ EngineQRegExp
Definition regexp.h:39
Syntax
Definition regexp.h:48
@ SyntaxDefault
Definition regexp.h:49
@ SyntaxFixedString
The default syntax.
Definition regexp.h:50
#define EDBEE_EXPORT
Definition exports.h:15
QT Acessibility has an issue with reporting blank lines between elements lines. defining 'WINDOWS_EMP...
Definition commentcommand.cpp:20