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