Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92208 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49597 invoked from network); 11 Apr 2016 23:25:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Apr 2016 23:25:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.215.50 mail-lf0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:33225] helo=mail-lf0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/33-28094-9623C075 for ; Mon, 11 Apr 2016 19:25:29 -0400 Received: by mail-lf0-f50.google.com with SMTP id e190so1837252lfe.0 for ; Mon, 11 Apr 2016 16:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=FyBt8QhZPEZ3kJNdz9iJf9I9Eza0uMcfp6G3Tu9M5ko=; b=sFEV5Wa+cRCZYJqR3nELZ2/mSYEaTAiMFXHB1SPn2KN0/lWVgtedrN1G7GfgHQvGYN LIF0AfURCX8/R4087Kgun4ucz00HjjCbSMRFYL37c25+D2rCZsFx8TOZe1ZtDfuijd9k CAUH4LxlquIMdc5bUwXdhRiZyZ4VfHZJP8BBUQj5bsW7Z/NV+DHI/9vpAwdDeJycOFxq Pwo4+48ys5qaUHRD3dVgpk2hsHJJZK6mzH6W8t0Rwv3qQp1SVuyNnZrfwtnGvn2g6GoG jlXPCh2h8ISQ70+ng2vI4dg0ij1f0Aazgglu5g3BrAuZRSxCFaJ6bzicApAOCPPR1ma8 rqQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=FyBt8QhZPEZ3kJNdz9iJf9I9Eza0uMcfp6G3Tu9M5ko=; b=d39dKpMng6yMYKAfVZ6jVIUVTk3lDfReyH2EhGQ5Ah8TzimOslpbVrkAXZK4FOiqVs +DJU0CZSi2RzCpfkF218jEplRMYb6OeXE7tC+YUfB6FbVOEH+17SRZXyR3UixX7LiHz9 rQSeA0BOCBOxAgn1Zn6CKTQPBBOlfg85UKh5eJmBFj/Tm0zHiTHUdzP50wfK097xSfX8 JijWyfqJuC7am0yS/7ZfEe3pccfrIRX620kPfPbhPOi/H3gAsET1HPYF22WY2jq3Welc qzJlGSNgY/LP6sllQN+Dcnp5Zy4rKlUydE2+i6eoCj7C+XOcyKFL/UCaN3fefHNdmE9x OQvA== X-Gm-Message-State: AOPr4FUe82QxUbadOgCKNdYLJ4dAD0wQmckfPze9gxvHv0vRPk7AeUyLT8V5ExWDb8qfZZRJHT4VLQzE28+9FQ== MIME-Version: 1.0 X-Received: by 10.25.23.195 with SMTP id 64mr33652lfx.82.1460417125467; Mon, 11 Apr 2016 16:25:25 -0700 (PDT) Sender: php@golemon.com Received: by 10.112.18.75 with HTTP; Mon, 11 Apr 2016 16:25:25 -0700 (PDT) X-Originating-IP: [107.198.91.68] In-Reply-To: <570C2EB8.4080009@gmail.com> References: <570C2EB8.4080009@gmail.com> Date: Mon, 11 Apr 2016 16:25:25 -0700 X-Google-Sender-Auth: aFPK41ZVc9w7bN87X3dS5QSAT-Y Message-ID: To: Stanislav Malyshev Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] IntlCharsetDetector From: pollita@php.net (Sara Golemon) On Mon, Apr 11, 2016 at 4:09 PM, Stanislav Malyshev wrote: > The API looks a bit strange - new IntlCharsetDetector($text) and then > detect(). Can't we just have detect([$text])? > I went with a direct wrapping of the underlying API because it always feels like we regret adding magic eventually. It's trivial for some composer installable library to wrap this into something nicer. In fact, one probably WOULD use a userspace library in order to provide fallback to mb_detect_encoding() on PHP < 7.1 That said, how do you feel about compromising by adding this function in addition to the raw API? function ucsdet_detect_encoding(string $text, string $hint = null, bool $filter = false) { $det = new IntlCharsetDetector($text); if ($hint !== null) { $det->setDeclaredEncoding($hint); } $det->enableInputFiltering($filter); return $det->detect()['name']; } That'll give simplicity for the 80% case (I have a string, I want a best guess) but still provide the true API for consideration of confidence and/or other guesses. -Sara