Mercurial > hg > isophonics-drupal-site
diff vendor/zendframework/zend-stdlib/src/StringWrapper/Intl.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/zendframework/zend-stdlib/src/StringWrapper/Intl.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,88 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Stdlib\StringWrapper; + +use Zend\Stdlib\Exception; + +class Intl extends AbstractStringWrapper +{ + /** + * List of supported character sets (upper case) + * + * @var string[] + */ + protected static $encodings = ['UTF-8']; + + /** + * Get a list of supported character encodings + * + * @return string[] + */ + public static function getSupportedEncodings() + { + return static::$encodings; + } + + /** + * Constructor + * + * @throws Exception\ExtensionNotLoadedException + */ + public function __construct() + { + if (!extension_loaded('intl')) { + throw new Exception\ExtensionNotLoadedException( + 'PHP extension "intl" is required for this wrapper' + ); + } + } + + /** + * Returns the length of the given string + * + * @param string $str + * @return int|false + */ + public function strlen($str) + { + return grapheme_strlen($str); + } + + /** + * Returns the portion of string specified by the start and length parameters + * + * @param string $str + * @param int $offset + * @param int|null $length + * @return string|false + */ + public function substr($str, $offset = 0, $length = null) + { + // Due fix of PHP #62759 The third argument returns an empty string if is 0 or null. + if ($length !== null) { + return grapheme_substr($str, $offset, $length); + } + + return grapheme_substr($str, $offset); + } + + /** + * Find the position of the first occurrence of a substring in a string + * + * @param string $haystack + * @param string $needle + * @param int $offset + * @return int|false + */ + public function strpos($haystack, $needle, $offset = 0) + { + return grapheme_strpos($haystack, $needle, $offset); + } +}