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
00273 bool execute(MatchVector &sub,
00274 const String &str,
00275 size_t index = 0,
00276 size_t count = 0,
00277 int eflags = 0);
00278 bool execute(MatchArray &sub,
00279 const String &str,
00280 size_t index = 0,
00281 size_t count = 0,
00282 int eflags = 0);
00283
00284
00310 StringArray capture(const String &str,
00311 size_t index = 0,
00312 size_t count = 0,
00313 int eflags = 0);
00314
00349 String replace(const String &str,
00350 const String &rep,
00351 bool global = false,
00352 int eflags = 0);
00353
00384 StringArray split (const String &str,
00385 bool empty = false,
00386 int eflags = 0);
00387
00413 StringArray grep (const StringArray &src,
00414 int eflags = 0);
00415
00441 bool match (const String &str,
00442 size_t index = 0,
00443 int eflags = 0) const;
00444
00445 private:
00446 pcre *m_pcre;
00447 int m_flags;
00448 mutable int m_ecode;
00449 mutable String m_error;
00450 String m_rxstr;
00451 };
00452
00453 }
00454
00455 #endif // BLOCXX_HAVE_PCRE_H
00456 #endif // BLOCXX_HAVE_PCRE
00457
00458 #endif // BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00459
00460