/
Intl.php
83 lines (75 loc) · 2.26 KB
/
Intl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Lithium: the most rad php framework
*
* @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
namespace lithium\g11n\multibyte\adapter;
/**
* The `Intl` class is an adapter which uses certain string functions from
* `ext/intl`. You will need to have the extension installed to use this adapter.
*
* Internally works with a fixed encoding of UTF-8. This means you can't use
* this adapter for anything different than UTF-8 encoded strings. Silently
* returns `null` or `false` when input string contains badly formed UTF-8
* sequences.
*
* @link http://php.net/manual/en/book.intl.php
*/
class Intl extends \lithium\core\Object {
/**
* Determines if this adapter is enabled by checking if the `intl` extension is loaded.
*
* @return boolean Returns `true` if enabled, otherwise `false`.
*/
public static function enabled() {
return extension_loaded('intl');
}
/**
* Here used as a multibyte enabled equivalent of `strlen()`.
*
* @link http://php.net/manual/en/function.grapheme-strlen.php
* @param string $string
* @return integer|void
*/
public function strlen($string) {
return grapheme_strlen($string);
}
/**
* Here used as a multibyte enabled equivalent of `strpos()`.
*
* @link http://php.net/manual/en/function.grapheme-strpos.php
* @param string $haystack
* @param string $needle
* @param integer $offset
* @return integer|boolean
*/
public function strpos($haystack, $needle, $offset) {
return grapheme_strpos($haystack, $needle, $offset);
}
/**
* Here used as a multibyte enabled equivalent of `strrpos()`.
*
* @link http://php.net/manual/en/function.grapheme-strpos.php
* @param string $haystack
* @param string $needle
* @return integer|boolean
*/
public function strrpos($haystack, $needle) {
return grapheme_strrpos($haystack, $needle);
}
/**
* Here used as a multibyte enabled equivalent of `substr()`.
*
* @link http://php.net/manual/en/function.grapheme-substr.php
* @param string $string
* @param integer $start
* @param integer $length
* @return string|boolean
*/
public function substr($string, $start, $length) {
return grapheme_substr($string, $start, $length);
}
}
?>