Annotation of parser3/src/types/pa_vregex.h, revision 1.5

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: 
1.5     ! misha      11: static const char * const IDENT_VREGEX_H="$Date: 2009-05-13 07:35:27 $";
1.1       misha      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: 
1.2       misha      41:        /// VRegex: count
                     42:        override int as_int() { return get_info_size(); }
                     43: 
                     44:        /// VRegex: count
                     45:        override double as_double() { return as_int(); }
1.1       misha      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
1.2       misha      54:        virtual bool is_defined() const { return as_bool(); }
1.1       misha      55: 
                     56:        /// VRegex: true
                     57:        override bool as_bool() const { return true; }
                     58: 
1.5     ! misha      59:        override Value* get_element(const String& aname);
        !            60: 
1.1       misha      61: public: // usage
                     62: 
                     63:        VRegex():
1.3       misha      64:                fcharset(0),
                     65:                fpattern(0),
1.5     ! misha      66:                foptions_cstr(0),
1.3       misha      67:                fcode(0),
                     68:                fextra(0),
                     69:                fstudied(false)
                     70:        {
                     71:                foptions[0]=0;
                     72:                foptions[1]=0;
                     73:        }
1.1       misha      74: 
                     75:        VRegex(Charset& acharset, const String* aregex, const String* aoptions):
1.3       misha      76:                fextra(0),
1.1       misha      77:                fstudied(false)
                     78:        {
                     79:                set(acharset, aregex, aoptions);
                     80:                compile();
                     81:        }
                     82: 
                     83:        ~VRegex(){
                     84:                if(fextra)
                     85:                        pcre_free(fextra);
                     86:                if(fcode)
                     87:                        pcre_free(fcode);
                     88:        }
                     89: 
                     90:        void set(Charset& acharset, const String* aregex, const String* aoptions);
                     91: 
                     92:        void compile();
                     93: 
                     94:        void study();
                     95: 
                     96:        int exec(const char* string, size_t string_len, int* ovector, int ovector_size, int prestart=0);
                     97: 
                     98:        // size_t info();
                     99: 
                    100:        size_t full_info(int type);
                    101: 
                    102:        size_t get_info_size();
                    103: 
                    104:        size_t get_study_size();
                    105: 
                    106:        size_t get_options();
                    107: 
                    108:        bool is_pre_post_match_needed(){
                    109:                return (foptions[1] & MF_NEED_PRE_POST_MATCH)!=0;
                    110:        }
                    111: 
                    112:        bool is_just_count(){
                    113:                return (foptions[1] & MF_JUST_COUNT_MATCHES)!=0;
                    114:        }
                    115: 
                    116:        bool is_global_search(){
                    117:                return (foptions[1] & MF_GLOBAL_SEARCH)!=0;
                    118:        }
                    119: 
                    120: private:
                    121:        static void regex_options(const String* options, int* result);
                    122: 
                    123: private:
                    124:        Charset* fcharset;
                    125:        const char* fpattern;
1.5     ! misha     126:        const char* foptions_cstr;
1.1       misha     127:        int foptions[2];
                    128: 
                    129:        pcre* fcode;
                    130:        pcre_extra* fextra;
                    131:        bool fstudied;
                    132: };
                    133: 
1.2       misha     134: 
                    135: class VRegexCleaner {
                    136: public:
                    137:        VRegex *vregex;
                    138: 
                    139:        VRegexCleaner(): vregex(0) { }
                    140: 
                    141:        ~VRegexCleaner(){
                    142:                if(vregex) delete vregex;
                    143:        }
                    144: 
                    145: };
                    146: 
1.1       misha     147: 
                    148: #endif

E-mail: