Skip to content

Commit

Permalink
Also add a valid_identifier_pve() that takes a start/end pair inste…
Browse files Browse the repository at this point in the history
…ad of s/len
  • Loading branch information
leonerd committed Nov 23, 2024
1 parent 071d70c commit 49b9a0b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -3766,6 +3766,10 @@ EXdpx |bool |validate_proto |NN SV *name \
|NULLOK SV *proto \
|bool warn \
|bool curstash
Adp |bool |valid_identifier_pve \
|NN const char *s \
|NN const char *end \
|U32 flags
Adp |bool |valid_identifier_pvn \
|NN const char *s \
|STRLEN len \
Expand Down
1 change: 1 addition & 0 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@
# define uvchr_to_utf8_flags(a,b,c) Perl_uvchr_to_utf8_flags(aTHX,a,b,c)
# define uvchr_to_utf8_flags_msgs(a,b,c,d) Perl_uvchr_to_utf8_flags_msgs(aTHX,a,b,c,d)
# define uvoffuni_to_utf8_flags_msgs(a,b,c,d) Perl_uvoffuni_to_utf8_flags_msgs(aTHX_ a,b,c,d)
# define valid_identifier_pve(a,b,c) Perl_valid_identifier_pve(aTHX_ a,b,c)
# define valid_identifier_pvn(a,b,c) Perl_valid_identifier_pvn(aTHX_ a,b,c)
# define valid_identifier_sv(a) Perl_valid_identifier_sv(aTHX_ a)
# define valid_utf8_to_uvchr Perl_valid_utf8_to_uvchr
Expand Down
5 changes: 5 additions & 0 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 30 additions & 9 deletions toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -13933,12 +13933,12 @@ Perl_parse_subsignature(pTHX_ U32 flags)
}

/*
=for apidoc valid_identifier_pvn
=for apidoc valid_identifier_pve
Returns true if the string given by C<s> whose length is C<len> would be
considered valid as a Perl identifier. That is, it must begin with a
character matching C<isIDFIRST>, followed by characters all matching
C<isIDCONT>. An empty string (i.e. when C<len> is zero) will return false.
Returns true if the string given by C<s> until C<end> would be considered
valid as a Perl identifier. That is, it must begin with a character matching
C<isIDFIRST>, followed by characters all matching C<isIDCONT>. An empty
string (i.e. when C<end> is C<s>) will return false.
If C<flags> contains the C<SVf_UTF8> bit, then the string is presumed to be
encoded in UTF-8, and suitable Unicode character test functions will be used.
Expand All @@ -13947,12 +13947,11 @@ encoded in UTF-8, and suitable Unicode character test functions will be used.
*/

bool
Perl_valid_identifier_pvn(pTHX_ const char *s, STRLEN len, U32 flags)
Perl_valid_identifier_pve(pTHX_ const char *s, const char *end, U32 flags)
{
PERL_ARGS_ASSERT_VALID_IDENTIFIER_PVN;
const char *end = s + len;
PERL_ARGS_ASSERT_VALID_IDENTIFIER_PVE;

if(!len)
if(end <= s)
return false;

if(flags & SVf_UTF8) {
Expand Down Expand Up @@ -13985,6 +13984,28 @@ Perl_valid_identifier_pvn(pTHX_ const char *s, STRLEN len, U32 flags)
return false;
}

/*
=for apidoc valid_identifier_pvn
Returns true if the string given by C<s> whose length is C<len> would be
considered valid as a Perl identifier. That is, it must begin with a
character matching C<isIDFIRST>, followed by characters all matching
C<isIDCONT>. An empty string (i.e. when C<len> is zero) will return false.
If C<flags> contains the C<SVf_UTF8> bit, then the string is presumed to be
encoded in UTF-8, and suitable Unicode character test functions will be used.
=cut
*/

bool
Perl_valid_identifier_pvn(pTHX_ const char *s, STRLEN len, U32 flags)
{
PERL_ARGS_ASSERT_VALID_IDENTIFIER_PVN;

return valid_identifier_pve(s, s + len, flags);
}

/*
=for apidoc valid_identifier_sv
Expand Down

0 comments on commit 49b9a0b

Please sign in to comment.