Annotation of parser3/src/classes/regex.C, revision 1.12
1.1 misha 1: /** @file
2: Parser: @b int parser class.
3:
1.11 moko 4: Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)
1.1 misha 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
6: */
7:
8: #include "classes.h"
9: #include "pa_vmethod_frame.h"
10:
11: #include "pa_request.h"
12: #include "pa_vint.h"
13: #include "pa_vregex.h"
14:
1.12 ! moko 15: volatile const char * IDENT_REGEX_C="$Id: regex.C,v 1.11 2017/02/07 22:00:29 moko Exp $";
1.7 moko 16:
1.1 misha 17: // class
18:
19: class MRegex: public Methoded {
1.2 misha 20: public: // VStateless_class
1.5 misha 21: Value* create_new_value(Pool&) { return new VRegex(); }
1.1 misha 22: public:
23: MRegex();
24: };
25:
26: // global variable
27:
1.9 moko 28: DECLARE_CLASS_VAR(regex, new MRegex);
1.1 misha 29:
30: // methods
31:
32: static void _create(Request& r, MethodParams& params) {
1.4 misha 33: const String& pattern=params.as_string(0, "regexp must not be code");
1.1 misha 34:
35: VRegex& vregex=GET_SELF(r, VRegex);
36:
1.12 ! moko 37: if(VRegex* aregex = static_cast<VRegex*>(params[0].as(VREGEX_TYPE))){
! 38: if(params.count()>1)
! 39: throw Exception(PARSER_RUNTIME, 0, "options can't be specified");
! 40: vregex.set(*aregex);
! 41: } else {
! 42: vregex.set(r.charsets.source(), &pattern, params.count()>1 ? ¶ms.as_string(1, OPTIONS_MUST_NOT_BE_CODE) : 0);
! 43: }
1.1 misha 44:
45: vregex.compile();
46:
47: vregex.study();
48: }
49:
50:
51: static void _size(Request& r, MethodParams&) {
52: VRegex& vregex=GET_SELF(r, VRegex);
1.10 moko 53: r.write(*new VInt(vregex.get_info_size()));
1.1 misha 54: }
55:
56: static void _study_size(Request& r, MethodParams&) {
57: VRegex& vregex=GET_SELF(r, VRegex);
1.10 moko 58: r.write(*new VInt(vregex.get_study_size()));
1.1 misha 59: }
60:
61: // constructor
62:
63: MRegex::MRegex(): Methoded("regex") {
1.12 ! moko 64: // ^regex::create[string|regex[;options]]
1.1 misha 65: add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2);
66:
67: // ^regex.info_size[]
68: add_native_method("size", Method::CT_DYNAMIC, _size, 0, 0);
69:
70: // ^regex.study_size[]
71: add_native_method("study_size", Method::CT_DYNAMIC, _study_size, 0, 0);
72:
73: }
1.2 misha 74:
E-mail: