Re: RFC Posted for str_begins and str_ends functions
| From: | Andrea Faulds | Date: | Wed, 10 Aug 2016 02:09:09 +0000 |
| Subject: | Re: RFC Posted for str_begins and str_ends functions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94982@lists.php.net to get a copy of this message | ||
Hi Will,
will@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_functionsI 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/