Annotation of parser3/src/types/pa_vregex.h, revision 1.1
1.1 ! misha 1: /** @file
! 2: Parser: @b regex class decls.
! 3:
! 4: Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)
! 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
! 6: */
! 7:
! 8: #ifndef PA_VREGEX_H
! 9: #define PA_VREGEX_H
! 10:
! 11: static const char * const IDENT_VREGEX_H="$Date: 2009-04-16 01:07:58 $";
! 12:
! 13: // include
! 14:
! 15: #include "classes.h"
! 16: #include "pa_common.h"
! 17: #include "pa_vstateless_object.h"
! 18: #include "pa_charset.h"
! 19: #include "pcre.h"
! 20:
! 21: // defines
! 22:
! 23: #define VREGEX_TYPE "regex"
! 24:
! 25: enum Match_feature {
! 26: MF_GLOBAL_SEARCH = 0x01,
! 27: MF_NEED_PRE_POST_MATCH = 0x02,
! 28: MF_JUST_COUNT_MATCHES = 0x04
! 29: };
! 30:
! 31: extern Methoded* regex_class;
! 32:
! 33: // VRegex
! 34: class VRegex: public VStateless_object {
! 35:
! 36: public: // Value
! 37:
! 38: override const char* type() const { return VREGEX_TYPE; }
! 39: override VStateless_class *get_class() { return regex_class; }
! 40:
! 41: /// VRegex: count
! 42: override int as_int() { return get_info_size(); }
! 43:
! 44: /// VRegex: count
! 45: override double as_double() { return as_int(); }
! 46:
! 47: /// VRegex: true
! 48: override bool is_evaluated_expr() const { return true; }
! 49:
! 50: /// VRegex: scalar
! 51: override Value& as_expr_result(bool/*return_string_as_is=false*/);
! 52:
! 53: /// VRegex: true
! 54: virtual bool is_defined() const { return true; }
! 55:
! 56: /// VRegex: true
! 57: override bool as_bool() const { return true; }
! 58:
! 59: public: // usage
! 60:
! 61: VRegex():
! 62: fstudied(false) { }
! 63:
! 64: VRegex(Charset& acharset, const String* aregex, const String* aoptions):
! 65: fstudied(false)
! 66: {
! 67: set(acharset, aregex, aoptions);
! 68: compile();
! 69: }
! 70:
! 71: ~VRegex(){
! 72: if(fextra)
! 73: pcre_free(fextra);
! 74: if(fcode)
! 75: pcre_free(fcode);
! 76: }
! 77:
! 78: void set(Charset& acharset, const String* aregex, const String* aoptions);
! 79:
! 80: void compile();
! 81:
! 82: void study();
! 83:
! 84: int exec(const char* string, size_t string_len, int* ovector, int ovector_size, int prestart=0);
! 85:
! 86: // size_t info();
! 87:
! 88: size_t full_info(int type);
! 89:
! 90: size_t get_info_size();
! 91:
! 92: size_t get_study_size();
! 93:
! 94: size_t get_options();
! 95:
! 96: bool is_pre_post_match_needed(){
! 97: return (foptions[1] & MF_NEED_PRE_POST_MATCH)!=0;
! 98: }
! 99:
! 100: bool is_just_count(){
! 101: return (foptions[1] & MF_JUST_COUNT_MATCHES)!=0;
! 102: }
! 103:
! 104: bool is_global_search(){
! 105: return (foptions[1] & MF_GLOBAL_SEARCH)!=0;
! 106: }
! 107:
! 108: private:
! 109: static void regex_options(const String* options, int* result);
! 110:
! 111: private:
! 112: Charset* fcharset;
! 113: const char* fpattern;
! 114: size_t fpattern_len;
! 115: int foptions[2];
! 116:
! 117: pcre* fcode;
! 118: pcre_extra* fextra;
! 119: bool fstudied;
! 120: };
! 121:
! 122:
! 123: class VRegexCleaner {
! 124: public:
! 125: VRegex *vregex;
! 126:
! 127: VRegexCleaner(): vregex(0) { }
! 128:
! 129: ~VRegexCleaner(){
! 130: if(vregex) delete vregex;
! 131: }
! 132:
! 133: };
! 134:
! 135:
! 136: #endif
E-mail: