edbee - Qt Editor Library
regexp.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <QString>
9 
10 namespace edbee {
11 
15 {
16 public:
17  virtual ~RegExpEngine() {}
18  virtual QString pattern() = 0;
19  virtual bool isValid() = 0;
20  virtual QString error() = 0;
21  virtual int indexIn( const QString& str, int offset ) = 0;
22  virtual int indexIn( const QChar* str, int offset, int length ) = 0;
23  virtual int lastIndexIn( const QString& str, int offset ) = 0;
24  virtual int lastIndexIn( const QChar* str, int offset, int length ) = 0;
25 
26  virtual int pos( int nth = 0 ) const = 0;
27  virtual int len( int nth = 0 ) const = 0;
28  virtual QString cap( int nth = 0 ) const = 0;
29 };
30 
31 
32 
36 class RegExp
37 {
38 public:
39  enum Engine {
40  EngineOniguruma = 1,
41  EngineQRegExp = 2
42 // QRegExp::RegExp 0 A rich Perl-like pattern matching syntax. This is the default.
43 // QRegExp::RegExp2 3 Like RegExp, but with greedy quantifiers. (Introduced in Qt 4.2.)
44 // 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.
45 // 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 "\".
46 // 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().
47 // QRegExp::W3CXmlSchema11 5 The pattern is a regular expression as defined by the W3C XML Schema 1.1 specification.
48  };
49 
50  enum Syntax {
52  SyntaxFixedString
53  };
54 
55 
56 
57  RegExp( const QString& pattern, bool caseSensitive=true, Syntax syntax=SyntaxDefault, Engine engine=EngineOniguruma );
58  virtual ~RegExp();
59 
60  static QString escape( const QString& str, Engine engine=EngineOniguruma );
61 
62  bool isValid() const;
63  QString errorString() const ;
64  QString pattern() const ;
65 
66 
67  int indexIn( const QString& str, int offset = 0 ); // const;
68  int indexIn( const QChar* str, int offset, int length );
69  int lastIndexIn( const QString& str, int offset=-1 );
70  int lastIndexIn( const QChar* str, int offset, int length );
71  int pos( int nth = 0 ) const;
72  int len( int nth = 0 ) const;
73  QString cap( int nth = 0) const;
74 
75 
77  int matchedLength() { return len(0); }
78 
79  // int cap( int nth = 0 ) const;
80 
81 private:
82  RegExpEngine* d_;
83 };
84 
85 } // edbee
int matchedLength()
matched length is equal to pos-0-length
Definition: regexp.h:77
virtual int indexIn(const QString &str, int offset)=0
Engine
Definition: regexp.h:39
virtual ~RegExpEngine()
Definition: regexp.h:17
The minimal engine we currently require for handling regexpt. It may grow in the future.
Definition: regexp.h:14
virtual int len(int nth=0) const =0
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
A class for matching QStrings with the Oniguruma API We need this Regular Expression library to be ab...
Definition: regexp.h:36
virtual QString error()=0
virtual int pos(int nth=0) const =0
virtual QString cap(int nth=0) const =0
virtual int lastIndexIn(const QString &str, int offset)=0
Definition: regexp.h:51
TestEngine & engine()
Definition: test.h:306
Syntax
Definition: regexp.h:50
virtual bool isValid()=0
virtual QString pattern()=0