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_POSIX_REGEX_HPP_INCLUDE_GUARD_HPP_
00035 #define BLOCXX_POSIX_REGEX_HPP_INCLUDE_GUARD_HPP_
00036 #include "blocxx/BLOCXX_config.h"
00037 #include "blocxx/RegExException.hpp"
00038
00039 #ifdef BLOCXX_HAVE_REGEX
00040 #include "blocxx/String.hpp"
00041 #include "blocxx/Array.hpp"
00042
00043 #ifdef BLOCXX_HAVE_REGEX_H
00044 #include <regex.h>
00045
00046 namespace BLOCXX_NAMESPACE
00047 {
00048
00058 class BLOCXX_COMMON_API PosixRegEx
00059 {
00060 public:
00067 typedef regmatch_t match_t;
00068
00072 typedef blocxx::Array<match_t> MatchArray;
00073
00077 PosixRegEx();
00078
00088 PosixRegEx(const String ®ex, int cflags = REG_EXTENDED);
00089
00098 PosixRegEx(const PosixRegEx &ref);
00099
00103 ~PosixRegEx();
00104
00112 PosixRegEx& operator = (const PosixRegEx &ref);
00113
00114
00136 bool compile(const String ®ex,
00137 int cflags = REG_EXTENDED);
00138
00145 int errorCode();
00146
00153 String errorString() const;
00154
00155
00159 String patternString() const;
00160
00164 int compileFlags() const;
00165
00169 bool isCompiled() const;
00170
00171
00237 bool execute(MatchArray &sub,
00238 const String &str,
00239 size_t index = 0,
00240 size_t count = 0,
00241 int eflags = 0);
00242
00269 StringArray capture(const String &str,
00270 size_t index = 0,
00271 size_t count = 0,
00272 int eflags = 0);
00273
00309 String replace(const String &str,
00310 const String &rep,
00311 bool global = false,
00312 int eflags = 0);
00313
00345 StringArray split (const String &str,
00346 bool empty = false,
00347 int eflags = 0);
00348
00375 StringArray grep (const StringArray &src,
00376 int eflags = 0);
00377
00403 bool match (const String &str,
00404 size_t index = 0,
00405 int eflags = 0) const;
00406
00407 private:
00408 bool compiled;
00409 int m_flags;
00410 mutable int m_ecode;
00411 mutable String m_error;
00412 String m_rxstr;
00413 regex_t m_regex;
00414 };
00415
00416 }
00417
00418 #endif // BLOCXX_HAVE_REGEX_H
00419 #endif // BLOCXX_HAVE_REGEX
00420
00421 #endif // BLOCXX_POSIX_REGEX_HPP_INCLUDE_GUARD_HPP_
00422
00423