develooper Front page | perl.perl5.porters | Postings from May 2017

RFC: Add new string comparison macros in handy.h

Thread Next
From:
Karl Williamson
Date:
May 11, 2017 15:25
Subject:
RFC: Add new string comparison macros in handy.h
Message ID:
816fb4ce-89c9-287e-cf7b-b79ecc249952@khwilliamson.com
I would like to add the macros given below to handy.h.  The situations 
they handle occur reasonably frequently in the core, and these can save 
developers from thinking they have to manually count the characters in a 
string.

I am not confident at all about the names, and would like to see if 
people have better ones.

I also would like to document memEQs, memLE, memLT, memGE, and memGT. 
And move all similar macros to a new section, "String comparison 
functions", from the current "Miscellaneous".

     strSTARTS_WITHs
             Test if the "NUL"-terminated string "s1" begins with the 
substring
             given by the string literal "s2", returning non-zero if so
             (including if the two are identical); zero otherwise.

                     bool    strSTARTS_WITHs(char* s1, char* s2)

     memSTARTS_WITHs
             Test if the string buffer "s1" with length "l1" begins with the
             substring given by the string literal "s2", returning 
non-zero if
             so (including if the two are identical); zero otherwise. The
             comparison does not include the final "NUL" of "s2". "s1" 
does not
             have to be "NUL"-terminated,

                     bool    memSTARTS_WITHs(char* s1, STRLEN l1, char* s2)

     memENDS_WITHs
             Test if the string buffer "s1" with length "l1" ends with the
             substring given by the string literal "s2", returning 
non-zero if
             so (including if the two are identical); zero otherwise. The
             comparison does not include the final "NUL" of "s2". "s1" 
does not
             have to be "NUL"-terminated,

                     bool    memENDS_WITHs(char* s1, STRLEN l1, char* s2)

     memFOO_STARTING_WITHs
             Test if the string buffer "s1" with length "l1" begins with the
             substring given by the string literal "s2", and that "s1" is
             longer than "s2", returning non-zero if so; zero otherwise. In
             other words, "s2" begins "s1" but is not all of "s1". The
             comparison does not include the final "NUL" of "s2". "s1" 
does not
             have to be "NUL"-terminated,

                     bool    memFOO_STARTING_WITHs(char* s1, STRLEN l1,
                                                   char* s2)

     memFOO_ENDING_WITHs
             Test if the string buffer "s1" with length "l1" ends with the
             substring given by the string literal "s2", and that "s1" is
             longer than "s2", returning non-zero if so; zero otherwise. In
             other words, "s2" ends "s1" but is not all of "s1". The 
comparison
             does not include the final "NUL" of "s2". "s1" does not 
have to be
             "NUL"-terminated,

                     bool    memFOO_ENDING_WITHs(char* s1, STRLEN l1,
                                                 char* s2)

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About