[TYPO3-core] RFC #15002: Enhancement of t3lib_div::isFirstPartOfStr
Michiel Roos [netcreators]
michiel at netcreators.com
Mon Jul 5 23:42:27 CEST 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 7/5/10 10:40 PM, Xavier Perseguers wrote:
> Hi,
>
>> I am not sure if this still matches the CGL, but I would write the
>> function like this:
>>
>> function isFirstPartOfStrNew ($str, $partStr) {
>> return (boolean)($partStr !== ''&& strpos($str, $partStr, 0) === 0);
>> }
>>
>> This is as fast as the first given function. see test below.
>
> I find it quite unreadable. If this is as fast, then use the first given
> function which is absolutely clear.
Yes, that's hard to read and not the fastest version either.
This one seems to be the fastest:
function isFirstPartOfStrNew3 ($str, $partStr) {
if ($partStr === '') return FALSE;
return (strpos($str, $partStr, 0) === 0);
}
It's also clear:
1 return false if $partStr is an empty string
2 otherwise use strpos to determine if $partStr is the first part of the
string
Please find attached a v3 and a new test file.
- --
Met vriendelijke groet / Warm regards,
Michiel Roos
Chief Technical Officer
Netcreators: Open Source, Open Minds, Open People
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkwyUbsACgkQLMRd8N/xuiw3LACfbGZB7/pU98rpWACgL6p5htXX
uIQAnjHrfc9vrjHJrPWvL4ST5sg6nFWf
=dNfD
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 15002_v3.diff
URL: <http://lists.typo3.org/pipermail/typo3-team-core/attachments/20100705/9d94cd86/attachment.asc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 15002_test_v5.php
Type: text/php
Size: 2445 bytes
Desc: not available
URL: <http://lists.typo3.org/pipermail/typo3-team-core/attachments/20100705/9d94cd86/attachment-0001.bin>
More information about the TYPO3-team-core
mailing list