Annotation of parser3/src/classes/regex.C, revision 1.16
1.1 misha 1: /** @file
2: Parser: @b int parser class.
3:
1.16 ! moko 4: Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com)
! 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 misha 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.16 ! moko 15: volatile const char * IDENT_REGEX_C="$Id: regex.C,v 1.15 2020/12/15 17:10: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) {
33: VRegex& vregex=GET_SELF(r, VRegex);
34:
1.12 moko 35: if(VRegex* aregex = static_cast<VRegex*>(params[0].as(VREGEX_TYPE))){
36: vregex.set(*aregex);
37: } else {
1.13 moko 38: const String& pattern=params.as_string(0, "regexp must not be code");
1.12 moko 39: vregex.set(r.charsets.source(), &pattern, params.count()>1 ? ¶ms.as_string(1, OPTIONS_MUST_NOT_BE_CODE) : 0);
40: }
1.1 misha 41:
42: vregex.compile();
43: vregex.study();
44: }
45:
46:
47: static void _size(Request& r, MethodParams&) {
48: VRegex& vregex=GET_SELF(r, VRegex);
1.10 moko 49: r.write(*new VInt(vregex.get_info_size()));
1.1 misha 50: }
51:
52: static void _study_size(Request& r, MethodParams&) {
53: VRegex& vregex=GET_SELF(r, VRegex);
1.10 moko 54: r.write(*new VInt(vregex.get_study_size()));
1.1 misha 55: }
56:
57: // constructor
58:
59: MRegex::MRegex(): Methoded("regex") {
1.12 moko 60: // ^regex::create[string|regex[;options]]
1.1 misha 61: add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2);
62:
63: // ^regex.info_size[]
64: add_native_method("size", Method::CT_DYNAMIC, _size, 0, 0);
65:
66: // ^regex.study_size[]
67: add_native_method("study_size", Method::CT_DYNAMIC, _study_size, 0, 0);
68:
69: }
1.2 misha 70:
E-mail: