--- parser3/src/classes/regex.C 2009/05/13 08:36:08 1.2 +++ parser3/src/classes/regex.C 2024/09/13 04:01:22 1.17 @@ -1,12 +1,10 @@ /** @file Parser: @b int parser class. - Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ -static const char * const IDENT_REGEX_C="$Date: 2009/05/13 08:36:08 $"; - #include "classes.h" #include "pa_vmethod_frame.h" @@ -14,52 +12,52 @@ static const char * const IDENT_REGEX_C= #include "pa_vint.h" #include "pa_vregex.h" +volatile const char * IDENT_REGEX_C="$Id: regex.C,v 1.17 2024/09/13 04:01:22 moko Exp $"; + // class class MRegex: public Methoded { public: // VStateless_class - Value* create_new_value(Pool&, HashStringValue&) { return new VRegex(); } + Value* create_new_value(Pool&) { return new VRegex(); } public: MRegex(); -public: // Methoded - bool used_directly() { return true; } }; // global variable -DECLARE_CLASS_VAR(regex, new MRegex, 0); +DECLARE_CLASS_VAR(regex, new MRegex); // methods static void _create(Request& r, MethodParams& params) { - Value& value=params.as_no_junction(0, "regexp must not be code"); - VRegex& vregex=GET_SELF(r, VRegex); - vregex.set(r.charsets.source(), - &value.as_string(), - params.count()>1?¶ms.as_no_junction(1, "options must not be code").as_string():0); + if(VRegex* aregex = dynamic_cast(¶ms[0])){ + vregex.set(*aregex); + } else { + const String& pattern=params.as_string(0, "regexp must not be code"); + vregex.set(r.charsets.source(), &pattern, params.count()>1 ? ¶ms.as_string(1, OPTIONS_MUST_NOT_BE_CODE) : 0); + } vregex.compile(); - vregex.study(); } static void _size(Request& r, MethodParams&) { VRegex& vregex=GET_SELF(r, VRegex); - r.write_no_lang(*new VInt(vregex.get_info_size())); + r.write(*new VInt(vregex.get_info_size())); } static void _study_size(Request& r, MethodParams&) { VRegex& vregex=GET_SELF(r, VRegex); - r.write_no_lang(*new VInt(vregex.get_study_size())); + r.write(*new VInt(vregex.get_study_size())); } // constructor MRegex::MRegex(): Methoded("regex") { - // ^regex::create[string[;options]] + // ^regex::create[string|regex[;options]] add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2); // ^regex.info_size[]