Annotation of parser3/src/classes/regex.C, revision 1.13
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.13 ! moko 15: volatile const char * IDENT_REGEX_C="$Id: regex.C,v 1.12 2018/01/19 00:27:43 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: if(params.count()>1)
37: throw Exception(PARSER_RUNTIME, 0, "options can't be specified");
38: vregex.set(*aregex);
39: } else {
1.13 ! moko 40: const String& pattern=params.as_string(0, "regexp must not be code");
1.12 moko 41: vregex.set(r.charsets.source(), &pattern, params.count()>1 ? ¶ms.as_string(1, OPTIONS_MUST_NOT_BE_CODE) : 0);
42: }
1.1 misha 43:
44: vregex.compile();
45: vregex.study();
46: }
47:
48:
49: static void _size(Request& r, MethodParams&) {
50: VRegex& vregex=GET_SELF(r, VRegex);
1.10 moko 51: r.write(*new VInt(vregex.get_info_size()));
1.1 misha 52: }
53:
54: static void _study_size(Request& r, MethodParams&) {
55: VRegex& vregex=GET_SELF(r, VRegex);
1.10 moko 56: r.write(*new VInt(vregex.get_study_size()));
1.1 misha 57: }
58:
59: // constructor
60:
61: MRegex::MRegex(): Methoded("regex") {
1.12 moko 62: // ^regex::create[string|regex[;options]]
1.1 misha 63: add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2);
64:
65: // ^regex.info_size[]
66: add_native_method("size", Method::CT_DYNAMIC, _size, 0, 0);
67:
68: // ^regex.study_size[]
69: add_native_method("study_size", Method::CT_DYNAMIC, _study_size, 0, 0);
70:
71: }
1.2 misha 72:
E-mail: