Hi Will,
w...@wkhudgins.info wrote:
I recently emailed the group about submitting an RFC for str_begins()
and str_ends() functions. The RFC has now been officially submitted and
is viewable at:
https://wiki.php.net/rfc/add_str_begin_and_end_functions
I like this RFC, I've long wanted a PHP equivalent to JavaScript and the
like's .startsWith()/.endsWith().
Two comments, however.
Firstly, I'm not sure if having control over case-sensitivity as part of
the function is necessary, as you can always lowercase the string
yourself. Furthermore, if the user is dealing with non-single-byte
strings (e.g. Unicode), traditional byte-by-byte case-insensitive
comparison is not going to work properly in all cases (e.g. ß vs. SS).
I'd rather we leave case-insensitivity out of the function, and let the
user call strtolower() or mb_strtolower(), as the case may be, themselves.
Secondly, in JavaScript, .startsWith()[1] and .endsWith()[2] have an
extra parameter for specifying the offset into the haystack (in the case
of startsWith) or the string length of the haystack (in the case of
endsWith). In Python,[3][4] there's *two* extra parameters, to let you
clip the haystack from both ends (like with substr, I think). Have you
considered these? They could replace the case-sensitivity parameter,
perhaps.
Thanks for your work!
[1]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
[2]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
[3]
https://docs.python.org/3/library/stdtypes.html?highlight=str.startswith#str.startswith
[4]
https://docs.python.org/3/library/stdtypes.html?highlight=str.endswith#str.endswith
--
Andrea Faulds
https://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php