Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119194 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28154 invoked from network); 21 Dec 2022 11:48:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Dec 2022 11:48:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 447E4180505 for ; Wed, 21 Dec 2022 03:48:43 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS30827 82.113.144.0/20 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Wed, 21 Dec 2022 03:48:43 -0800 (PST) Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id A813810C025; Wed, 21 Dec 2022 11:48:42 +0000 (GMT) Date: Wed, 21 Dec 2022 11:48:42 +0000 (GMT) X-X-Sender: derick@singlemalt.home.derickrethans.nl To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= cc: PHP Developers Mailing List In-Reply-To: Message-ID: References: User-Agent: Alpine 2.23 (DEB 453 2020-06-18) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-286486410-1671621541=:462551" Subject: Re: [PHP-DEV] [RFC] Unicode Text Processing From: derick@php.net (Derick Rethans) --8323329-286486410-1671621541=:462551 Content-Type: text/plain; CHARSET=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 16 Dec 2022, Tim D=C3=BCsterhus wrote: > Hi >=20 > On 12/16/22 14:55, Derick Rethans wrote: > > > ---------- > > >=20 > > > getPositionOfFirstOccurrence(): > > >=20 > > > I agree this is too long. How about: > > >=20 > > > - findOffset() > > > - findOffsetLast() > > >=20 > > > And for returnFromFirstOccurence(): > > >=20 > > > - startingWith() > > > - startingWithLast() > >=20 > > I have included these as suggested names. I suspect we'll get more=20 > > :-) > >=20 >=20 > You accidentally put 'startingWithLast' into the 'contains' section. Oops, fixed. > But thinking about the name a little more: 'At' instead of 'With'=20 > might be a little more appropriate, because $a->startingWith($b) could=20 > also mean '$b . $a' =E2=80=A6 I've added that as a suggested name too. > which brings me to: >=20 > ---------- >=20 > 1. How is concatenation expected to work? Will '.' be overloaded or shoul= d > folks use: >=20 > \Text::join([ > $prefix, > '-' > $suffix, > ], ''); >=20 > or similar? Perhaps an explicit \Text::concat(=E2=80=A6) method should be= provided? I guess we can overload the . operator too, but I would still also add=20 an explicit method. I've added that to the RFC. =20 > ---------- >=20 > 2. As I've noted in the discussion for List\unique: I think iterators sho= uld > not be second-class citizen to arrays. Thus I propose to change \Text::jo= in() > to: >=20 > /** @param iterable<\Text|string> $elements */ > public static function join(iterable $elements, \Text|string $separator, > string $collator =3D null): \Text >=20 > This would then allow stuff like: >=20 > Text::join($someText->getWordIterator(), '-') >=20 > to insert `-` in-between each word. Indeed, there is no reason why it should be a simple array, and I've=20 updated the RFC accordingly. > ---------- >=20 > 3. Inversely: Should \Text->split() only guarantee 'iterable', instead of > 'array' as its return type? That is trickier, as a return value can't be a union. I suppose we could=20 signal that we return an iterable, but start by always returning an=20 array. That way if we want to expand this to an actual iterator we can,=20 without breaking LSP. Before making that change, I'd like to hear some other opinions on this. >=20 > ---------- >=20 > 4. How is equality comparisons expected to work? Will '=3D=3D' be overloa= ded? > Should users use 'compareWith(=E2=80=A6) =3D=3D=3D 0'? Should an 'equals(= )' method be > provided? '=3D=3D' will be overloaded. It's mentioned in the ''compareWith'' method.= =20 I have added an equals method, as I think that makes sense. cheers, Derick --=20 https://derickrethans.nl | https://xdebug.org | https://dram.io Author of Xdebug. Like it? Consider supporting me: https://xdebug.org/suppo= rt Host of PHP Internals News: https://phpinternals.news mastodon: @derickr@phpc.social @xdebug@phpc.social twitter: @derickr and @xdebug --8323329-286486410-1671621541=:462551--