On Mon, Apr 11, 2016 at 4:09 PM, Stanislav Malyshev <smalys...@gmail.com> 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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to