annotate vendor/zendframework/zend-stdlib/src/StringWrapper/Intl.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 7a779792577d
children
rev   line source
Chris@0 1 <?php
Chris@0 2 /**
Chris@0 3 * Zend Framework (http://framework.zend.com/)
Chris@0 4 *
Chris@0 5 * @link http://github.com/zendframework/zf2 for the canonical source repository
Chris@0 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
Chris@0 7 * @license http://framework.zend.com/license/new-bsd New BSD License
Chris@0 8 */
Chris@0 9
Chris@0 10 namespace Zend\Stdlib\StringWrapper;
Chris@0 11
Chris@0 12 use Zend\Stdlib\Exception;
Chris@0 13
Chris@0 14 class Intl extends AbstractStringWrapper
Chris@0 15 {
Chris@0 16 /**
Chris@0 17 * List of supported character sets (upper case)
Chris@0 18 *
Chris@0 19 * @var string[]
Chris@0 20 */
Chris@0 21 protected static $encodings = ['UTF-8'];
Chris@0 22
Chris@0 23 /**
Chris@0 24 * Get a list of supported character encodings
Chris@0 25 *
Chris@0 26 * @return string[]
Chris@0 27 */
Chris@0 28 public static function getSupportedEncodings()
Chris@0 29 {
Chris@0 30 return static::$encodings;
Chris@0 31 }
Chris@0 32
Chris@0 33 /**
Chris@0 34 * Constructor
Chris@0 35 *
Chris@0 36 * @throws Exception\ExtensionNotLoadedException
Chris@0 37 */
Chris@0 38 public function __construct()
Chris@0 39 {
Chris@12 40 if (! extension_loaded('intl')) {
Chris@0 41 throw new Exception\ExtensionNotLoadedException(
Chris@0 42 'PHP extension "intl" is required for this wrapper'
Chris@0 43 );
Chris@0 44 }
Chris@0 45 }
Chris@0 46
Chris@0 47 /**
Chris@0 48 * Returns the length of the given string
Chris@0 49 *
Chris@0 50 * @param string $str
Chris@0 51 * @return int|false
Chris@0 52 */
Chris@0 53 public function strlen($str)
Chris@0 54 {
Chris@0 55 return grapheme_strlen($str);
Chris@0 56 }
Chris@0 57
Chris@0 58 /**
Chris@0 59 * Returns the portion of string specified by the start and length parameters
Chris@0 60 *
Chris@0 61 * @param string $str
Chris@0 62 * @param int $offset
Chris@0 63 * @param int|null $length
Chris@0 64 * @return string|false
Chris@0 65 */
Chris@0 66 public function substr($str, $offset = 0, $length = null)
Chris@0 67 {
Chris@0 68 // Due fix of PHP #62759 The third argument returns an empty string if is 0 or null.
Chris@0 69 if ($length !== null) {
Chris@0 70 return grapheme_substr($str, $offset, $length);
Chris@0 71 }
Chris@0 72
Chris@0 73 return grapheme_substr($str, $offset);
Chris@0 74 }
Chris@0 75
Chris@0 76 /**
Chris@0 77 * Find the position of the first occurrence of a substring in a string
Chris@0 78 *
Chris@0 79 * @param string $haystack
Chris@0 80 * @param string $needle
Chris@0 81 * @param int $offset
Chris@0 82 * @return int|false
Chris@0 83 */
Chris@0 84 public function strpos($haystack, $needle, $offset = 0)
Chris@0 85 {
Chris@0 86 return grapheme_strpos($haystack, $needle, $offset);
Chris@0 87 }
Chris@0 88 }