Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75157 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65312 invoked from network); 30 Jun 2014 23:25:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jun 2014 23:25:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=kris.craig@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=kris.craig@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.46 as permitted sender) X-PHP-List-Original-Sender: kris.craig@gmail.com X-Host-Fingerprint: 209.85.219.46 mail-oa0-f46.google.com Received: from [209.85.219.46] ([209.85.219.46:36931] helo=mail-oa0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/B7-19922-FF1F1B35 for ; Mon, 30 Jun 2014 19:25:52 -0400 Received: by mail-oa0-f46.google.com with SMTP id m1so9578012oag.5 for ; Mon, 30 Jun 2014 16:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=759Ud7GJG9jYrkPWqCFwSnkKCoERKtsud9Z7+de0s2o=; b=OKImAmdsATP6FoN/q2Z4q9kHVUVKd0odrifs0D8ysAvrVhq1iVLoELVNi5Ux+hIEU9 +Klyc8FCM8xMjgDcWRbuDt0JB7M0sSQObtF7Nki4/otRu1PpaIE9xdEnJEwGxITO7F1g /Y5HpUuT7VYn2ajxDA8yBNHSucSbTYexialkOWY4DOFRgwWh1bMhTCIkIkhwF3yE6gsu y80845y2wphLVf9BaUxw9amjb/AQUFZYvC9YtGLG1pO5X+knVrUDUMdX8J+AH1yLkvWr itpPAKeROzxc9Qw/6FxUeNiodbNQ7OyNRV696XPdZWECMNgPCYk2JOcAKWjHczNBVR07 TzXg== MIME-Version: 1.0 X-Received: by 10.182.19.196 with SMTP id h4mr46283711obe.20.1404170749494; Mon, 30 Jun 2014 16:25:49 -0700 (PDT) Received: by 10.202.15.72 with HTTP; Mon, 30 Jun 2014 16:25:49 -0700 (PDT) In-Reply-To: <53B1590F.5070009@gmail.com> References: <679D0316-74C5-4AEC-9097-5E9793937469@ajf.me> <53B1590F.5070009@gmail.com> Date: Mon, 30 Jun 2014 16:25:49 -0700 Message-ID: To: Rowan Collins Cc: PHP internals list Content-Type: multipart/alternative; boundary=001a11c246e6ba4aa104fd15fadf Subject: Re: [PHP-DEV] Re: ucwords() vs title case From: kris.craig@gmail.com (Kris Craig) --001a11c246e6ba4aa104fd15fadf Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Jun 30, 2014 at 5:33 AM, Rowan Collins wrote: > Andrea Faulds wrote (on 30/06/2014): > >> On 30 Jun 2014, at 12:54, Tjerk Meesters >> wrote: >> >> Hi internals, >>> >>> I came across this old bug: https://bugs.php.net/bug.php?id=3D34407 >>> >>> >>> >>> Personally I find that the latter is too much of a departure from what = we >>> currently have; a compromise could be to treat punctuation as a word >>> delimiter. >>> >> Hmm. Why not make it follow what \b in a regex would do, looking for >> =E2=80=9Cword boundaries=E2=80=9D? >> > > Unfortunately, the cleverer you try to be, the more edge cases you find. > For instance, using \b will capitalise the 's' after an apostrophe, e.g. = in > "Andrea'S Suggestion". > > The function we have in our code base at the moment looks like this: > > function smart_uc_words($string) > { > $string =3D strtolower(trim($string)); > // Capitalise any word char preceded by a non-word char other tha= n > an apostrophe > $string =3D preg_replace_callback('/(? return strtoupper($m[1]); }, $string); > // Capitalise any word char which comes between an apostrophe and > another word char > $string =3D preg_replace_callback('/(?<=3D\')(\w)(?=3D\w)/', > function($m){ return strtoupper($m[1]); }, $string); > > return $string; > } > What about leaving the default behavior as-is but adding an optional argument to specify how to determine these boundaries? So if you did something like ucwords( "hello, world!", '\b' ) or ucwords( "hello, world!", array( ' ', '.', ... ) ), the user could control the behavior while existing ucwords( $arg ) code would behave as it does now without any BC. --Kris --001a11c246e6ba4aa104fd15fadf--