00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00034 #ifndef BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00035 #define BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00036 #include "blocxx/BLOCXX_config.h"
00037 #include "blocxx/RegExException.hpp"
00038
00039 #ifdef BLOCXX_HAVE_PCRE
00040 #include "blocxx/String.hpp"
00041 #include "blocxx/Array.hpp"
00042
00043 #ifdef BLOCXX_HAVE_PCRE_H
00044 #include <pcre.h>
00045
00046 namespace BLOCXX_NAMESPACE
00047 {
00048
00059 class BLOCXX_COMMON_API PerlRegEx
00060 {
00061 public:
00067 typedef blocxx::Array<int> MatchVector;
00068
00070 struct match_t {
00071 int rm_so;
00072 int rm_eo;
00073 };
00074
00076 typedef blocxx::Array<match_t> MatchArray;
00077
00081 PerlRegEx();
00082
00090 PerlRegEx(const String ®ex, int cflags = 0);
00091
00100 PerlRegEx(const PerlRegEx &ref);
00101
00105 ~PerlRegEx();
00106
00114 PerlRegEx& operator = (const PerlRegEx &ref);
00115
00145 bool compile(const String ®ex,
00146 int cflags = 0);
00147
00161 int errorCode();
00162
00169 String errorString() const;
00170
00174 String patternString() const;
00175
00179 int compileFlags() const;
00180
00184 bool isCompiled() const;
00185
00272 bool execute(MatchVector &sub,
00273 const String &str,
00274 size_t index = 0,
00275 size_t count = 0,
00276 int eflags = 0);
00277 bool execute(MatchArray &sub,
00278 const String &str,
00279 size_t index = 0,
00280 size_t count = 0,
00281 int eflags = 0);
00282
00283
00309 StringArray capture(const String &str,
00310 size_t index = 0,
00311 size_t count = 0,
00312 int eflags = 0);
00313
00348 String replace(const String &str,
00349 const String &rep,
00350 bool global = false,
00351 int eflags = 0);
00352
00383 StringArray split (const String &str,
00384 bool empty = false,
00385 int eflags = 0);
00386
00412 StringArray grep (const StringArray &src,
00413 int eflags = 0);
00414
00440 bool match (const String &str,
00441 size_t index = 0,
00442 int eflags = 0) const;
00443
00444 private:
00445 pcre *m_pcre;
00446 int m_flags;
00447 mutable int m_ecode;
00448 mutable String m_error;
00449 String m_rxstr;
00450 };
00451
00452 }
00453
00454 #endif // BLOCXX_HAVE_PCRE_H
00455 #endif // BLOCXX_HAVE_PCRE
00456
00457 #endif // BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00458
00459