📄 perlreapi.1
字号:
.Vb 2\& if (flags & RXf_SPLIT && r\->prelen == 1 && r\->precomp[0] == \*(Aq \*(Aq)\& r\->extflags |= (RXf_SKIPWHITE|RXf_WHITE);.Ve.PPThese flags can be set during compilation to enable optimizations inthe \f(CW\*(C`split\*(C'\fR operator..IP "RXf_SKIPWHITE" 4.IX Item "RXf_SKIPWHITE"If the flag is present in \f(CW\*(C`rx\->extflags\*(C'\fR \f(CW\*(C`split\*(C'\fR will deletewhitespace from the start of the subject string before it's operatedon. What is considered whitespace depends on whether the subject is a\&\s-1UTF\-8\s0 string and whether the \f(CW\*(C`RXf_PMf_LOCALE\*(C'\fR flag is set..SpIf RXf_WHITE is set in addition to this flag \f(CW\*(C`split\*(C'\fR will behave like\&\f(CW\*(C`split " "\*(C'\fR under the perl engine..IP "RXf_START_ONLY" 4.IX Item "RXf_START_ONLY"Tells the split operator to split the target string on newlines(\f(CW\*(C`\en\*(C'\fR) without invoking the regex engine..SpPerl's engine sets this if the pattern is \f(CW\*(C`/^/\*(C'\fR (\f(CW\*(C`plen == 1 && *exp== \*(Aq^\*(Aq\*(C'\fR), even under \f(CW\*(C`/^/s\*(C'\fR, see split. Of course adifferent regex engine might want to use the same optimizationswith a different syntax..IP "RXf_WHITE" 4.IX Item "RXf_WHITE"Tells the split operator to split the target string on whitespacewithout invoking the regex engine. The definition of whitespace variesdepending on whether the target string is a \s-1UTF\-8\s0 string and onwhether RXf_PMf_LOCALE is set..SpPerl's engine sets this flag if the pattern is \f(CW\*(C`\es+\*(C'\fR..IP "RXf_NULL" 4.IX Item "RXf_NULL"Tells the split operator to split the target string oncharacters. The definition of character varies depending on whetherthe target string is a \s-1UTF\-8\s0 string..SpPerl's engine sets this flag on empty patterns, this optimizationmakes \f(CW\*(C`split //\*(C'\fR much faster than it would otherwise be. It's evenfaster than \f(CW\*(C`unpack\*(C'\fR..Sh "exec".IX Subsection "exec".Vb 4\& I32 exec(pTHX_ REGEXP * const rx,\& char *stringarg, char* strend, char* strbeg,\& I32 minend, SV* screamer,\& void* data, U32 flags);.Ve.PPExecute a regexp..Sh "intuit".IX Subsection "intuit".Vb 3\& char* intuit(pTHX_ REGEXP * const rx,\& SV *sv, char *strpos, char *strend,\& const U32 flags, struct re_scream_pos_data_s *data);.Ve.PPFind the start position where a regex match should be attempted,or possibly whether the regex engine should not be run because thepattern can't match. This is called as appropriate by the coredepending on the values of the extflags member of the regexpstructure..Sh "checkstr".IX Subsection "checkstr".Vb 1\& SV* checkstr(pTHX_ REGEXP * const rx);.Ve.PPReturn a \s-1SV\s0 containing a string that must appear in the pattern. Usedby \f(CW\*(C`split\*(C'\fR for optimising matches..Sh "free".IX Subsection "free".Vb 1\& void free(pTHX_ REGEXP * const rx);.Ve.PPCalled by perl when it is freeing a regexp pattern so that the enginecan release any resources pointed to by the \f(CW\*(C`pprivate\*(C'\fR member of theregexp structure. This is only responsible for freeing private data;perl will handle releasing anything else contained in the regexp structure..Sh "Numbered capture callbacks".IX Subsection "Numbered capture callbacks"Called to get/set the value of \f(CW\*(C`$\`\*(C'\fR, \f(CW\*(C`$\*(Aq\*(C'\fR, \f(CW$&\fR and their namedequivalents, ${^PREMATCH}, ${^POSTMATCH} and $^{\s-1MATCH\s0}, as well as thenumbered capture buffers (\f(CW$1\fR, \f(CW$2\fR, ...)..PPThe \f(CW\*(C`paren\*(C'\fR parameter will be \f(CW\*(C`\-2\*(C'\fR for \f(CW\*(C`$\`\*(C'\fR, \f(CW\*(C`\-1\*(C'\fR for \f(CW\*(C`$\*(Aq\*(C'\fR, \f(CW0\fRfor \f(CW$&\fR, \f(CW1\fR for \f(CW$1\fR and so forth..PPThe names have been chosen by analogy with Tie::Scalar methodsnames with an additional \fB\s-1LENGTH\s0\fR callback for efficiency. Howevernamed capture variables are currently not tied internally butimplemented via magic..PP\fInumbered_buff_FETCH\fR.IX Subsection "numbered_buff_FETCH".PP.Vb 2\& void numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren,\& SV * const sv);.Ve.PPFetch a specified numbered capture. \f(CW\*(C`sv\*(C'\fR should be set to the scalarto return, the scalar is passed as an argument rather than beingreturned from the function because when it's called perl already has ascalar to store the value, creating another one would beredundant. The scalar can be set with \f(CW\*(C`sv_setsv\*(C'\fR, \f(CW\*(C`sv_setpvn\*(C'\fR andfriends, see perlapi..PPThis callback is where perl untaints its own capture variables undertaint mode (see perlsec). See the \f(CW\*(C`Perl_reg_numbered_buff_fetch\*(C'\fRfunction in \fIregcomp.c\fR for how to untaint capture variables ifthat's something you'd like your engine to do as well..PP\fInumbered_buff_STORE\fR.IX Subsection "numbered_buff_STORE".PP.Vb 2\& void (*numbered_buff_STORE) (pTHX_ REGEXP * const rx, const I32 paren,\& SV const * const value);.Ve.PPSet the value of a numbered capture variable. \f(CW\*(C`value\*(C'\fR is the scalarthat is to be used as the new value. It's up to the engine to makesure this is used as the new value (or reject it)..PPExample:.PP.Vb 4\& if ("ook" =~ /(o*)/) {\& # \`paren\*(Aq will be \`1\*(Aq and \`value\*(Aq will be \`ee\*(Aq\& $1 =~ tr/o/e/;\& }.Ve.PPPerl's own engine will croak on any attempt to modify the capturevariables, to do this in another engine use the following callback(copied from \f(CW\*(C`Perl_reg_numbered_buff_store\*(C'\fR):.PP.Vb 7\& void\& Example_reg_numbered_buff_store(pTHX_ REGEXP * const rx, const I32 paren,\& SV const * const value)\& {\& PERL_UNUSED_ARG(rx);\& PERL_UNUSED_ARG(paren);\& PERL_UNUSED_ARG(value);\&\& if (!PL_localizing)\& Perl_croak(aTHX_ PL_no_modify);\& }.Ve.PPActually perl will not \fIalways\fR croak in a statement that lookslike it would modify a numbered capture variable. This is because the\&\s-1STORE\s0 callback will not be called if perl can determine that itdoesn't have to modify the value. This is exactly how tied variablesbehave in the same situation:.PP.Vb 2\& package CaptureVar;\& use base \*(AqTie::Scalar\*(Aq;\&\& sub TIESCALAR { bless [] }\& sub FETCH { undef }\& sub STORE { die "This doesn\*(Aqt get called" }\&\& package main;\&\& tie my $sv => "CatptureVar";\& $sv =~ y/a/b/;.Ve.PPBecause \f(CW$sv\fR is \f(CW\*(C`undef\*(C'\fR when the \f(CW\*(C`y///\*(C'\fR operator is applied to itthe transliteration won't actually execute and the program won't\&\f(CW\*(C`die\*(C'\fR. This is different to how 5.8 and earlier versions behavedsince the capture variables were \s-1READONLY\s0 variables then, now they'lljust die when assigned to in the default engine..PP\fInumbered_buff_LENGTH\fR.IX Subsection "numbered_buff_LENGTH".PP.Vb 2\& I32 numbered_buff_LENGTH (pTHX_ REGEXP * const rx, const SV * const sv,\& const I32 paren);.Ve.PPGet the \f(CW\*(C`length\*(C'\fR of a capture variable. There's a special callbackfor this so that perl doesn't have to do a \s-1FETCH\s0 and run \f(CW\*(C`length\*(C'\fR onthe result, since the length is (in perl's case) known from an offsetstored in \f(CW\*(C`<rx\-\*(C'\fRoffs> this is much more efficient:.PP.Vb 3\& I32 s1 = rx\->offs[paren].start;\& I32 s2 = rx\->offs[paren].end;\& I32 len = t1 \- s1;.Ve.PPThis is a little bit more complex in the case of \s-1UTF\-8\s0, see what\&\f(CW\*(C`Perl_reg_numbered_buff_length\*(C'\fR does withis_utf8_string_loclen..Sh "Named capture callbacks".IX Subsection "Named capture callbacks"Called to get/set the value of \f(CW\*(C`%+\*(C'\fR and \f(CW\*(C`%\-\*(C'\fR as well as by someutility functions in re..PPThere are two callbacks, \f(CW\*(C`named_buff\*(C'\fR is called in all the cases the\&\s-1FETCH\s0, \s-1STORE\s0, \s-1DELETE\s0, \s-1CLEAR\s0, \s-1EXISTS\s0 and \s-1SCALAR\s0 Tie::Hash callbackswould be on changes to \f(CW\*(C`%+\*(C'\fR and \f(CW\*(C`%\-\*(C'\fR and \f(CW\*(C`named_buff_iter\*(C'\fR in thesame cases as \s-1FIRSTKEY\s0 and \s-1NEXTKEY\s0..PPThe \f(CW\*(C`flags\*(C'\fR parameter can be used to determine which of theseoperations the callbacks should respond to, the following flags arecurrently defined:.PPWhich Tie::Hash operation is being performed from the Perl level on\&\f(CW\*(C`%+\*(C'\fR or \f(CW\*(C`%+\*(C'\fR, if any:.PP.Vb 8\& RXapif_FETCH\& RXapif_STORE\& RXapif_DELETE\& RXapif_CLEAR\& RXapif_EXISTS\& RXapif_SCALAR\& RXapif_FIRSTKEY\& RXapif_NEXTKEY.Ve.PPWhether \f(CW\*(C`%+\*(C'\fR or \f(CW\*(C`%\-\*(C'\fR is being operated on, if any..PP.Vb 2\& RXapif_ONE /* %+ */\& RXapif_ALL /* %\- */.Ve.PPWhether this is being called as \f(CW\*(C`re::regname\*(C'\fR, \f(CW\*(C`re::regnames\*(C'\fR or\&\f(CW\*(C`re::regnames_count\*(C'\fR, if any. The first two will be combined with\&\f(CW\*(C`RXapif_ONE\*(C'\fR or \f(CW\*(C`RXapif_ALL\*(C'\fR..PP.Vb 3\& RXapif_REGNAME\& RXapif_REGNAMES\& RXapif_REGNAMES_COUNT.Ve.PPInternally \f(CW\*(C`%+\*(C'\fR and \f(CW\*(C`%\-\*(C'\fR are implemented with a real tied interfacevia Tie::Hash::NamedCapture. The methods in that package will callback into these functions. However the usage ofTie::Hash::NamedCapture for this purpose might change in futurereleases. For instance this might be implemented by magic instead(would need an extension to mgvtbl)..PP\fInamed_buff\fR.IX Subsection "named_buff".PP.Vb 2\& SV* (*named_buff) (pTHX_ REGEXP * const rx, SV * const key,\& SV * const value, U32 flags);.Ve.PP\fInamed_buff_iter\fR.IX Subsection "named_buff_iter".PP.Vb 2\& SV* (*named_buff_iter) (pTHX_ REGEXP * const rx, const SV * const lastkey,\& const U32 flags);.Ve.Sh "qr_package".IX Subsection "qr_package".Vb 1\& SV* qr_package(pTHX_ REGEXP * const rx);.Ve.PPThe package the qr// magic object is blessed into (as seen by \f(CW\*(C`refqr//\*(C'\fR). It is recommended that engines change this to their packagename for identification regardless of whether they implement methodson the object..PPThe package this method returns should also have the internal\&\f(CW\*(C`Regexp\*(C'\fR package in its \f(CW@ISA\fR. \f(CW\*(C`qr//\-\*(C'\fRisa(\*(L"Regexp\*(R")> should alwaysbe true regardless of what engine is being used..PPExample implementation might be:.PP.Vb 6\& SV*\& Example_qr_package(pTHX_ REGEXP * const rx)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -