Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Stdlib / StringWrapper / Native.php
blob978b731118d096055d7a008847dcdec54c40dfd2
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Stdlib\StringWrapper;
12 use Zend\Stdlib\Exception;
13 use Zend\Stdlib\StringUtils;
15 class Native extends AbstractStringWrapper
17 /**
18 * The character encoding working on
19 * (overwritten to change defaut encoding)
21 * @var string
23 protected $encoding = 'ASCII';
25 /**
26 * Check if the given character encoding is supported by this wrapper
27 * and the character encoding to convert to is also supported.
29 * @param string $encoding
30 * @param string|null $convertEncoding
31 * @return bool
33 public static function isSupported($encoding, $convertEncoding = null)
35 $encodingUpper = strtoupper($encoding);
36 $supportedEncodings = static::getSupportedEncodings();
38 if (!in_array($encodingUpper, $supportedEncodings)) {
39 return false;
42 // This adapter doesn't support to convert between encodings
43 if ($convertEncoding !== null && $encodingUpper !== strtoupper($convertEncoding)) {
44 return false;
47 return true;
50 /**
51 * Get a list of supported character encodings
53 * @return string[]
55 public static function getSupportedEncodings()
57 return StringUtils::getSingleByteEncodings();
60 /**
61 * Set character encoding working with and convert to
63 * @param string $encoding The character encoding to work with
64 * @param string|null $convertEncoding The character encoding to convert to
65 * @return StringWrapperInterface
67 public function setEncoding($encoding, $convertEncoding = null)
69 $supportedEncodings = static::getSupportedEncodings();
71 $encodingUpper = strtoupper($encoding);
72 if (!in_array($encodingUpper, $supportedEncodings)) {
73 throw new Exception\InvalidArgumentException(
74 'Wrapper doesn\'t support character encoding "' . $encoding . '"'
78 if ($encodingUpper !== strtoupper($convertEncoding)) {
79 $this->convertEncoding = $encodingUpper;
82 if ($convertEncoding !== null) {
83 if ($encodingUpper !== strtoupper($convertEncoding)) {
84 throw new Exception\InvalidArgumentException(
85 'Wrapper doesn\'t support to convert between character encodings'
89 $this->convertEncoding = $encodingUpper;
90 } else {
91 $this->convertEncoding = null;
93 $this->encoding = $encodingUpper;
95 return $this;
98 /**
99 * Returns the length of the given string
101 * @param string $str
102 * @return int|false
104 public function strlen($str)
106 return strlen($str);
110 * Returns the portion of string specified by the start and length parameters
112 * @param string $str
113 * @param int $offset
114 * @param int|null $length
115 * @return string|false
117 public function substr($str, $offset = 0, $length = null)
119 return substr($str, $offset, $length);
123 * Find the position of the first occurrence of a substring in a string
125 * @param string $haystack
126 * @param string $needle
127 * @param int $offset
128 * @return int|false
130 public function strpos($haystack, $needle, $offset = 0)
132 return strpos($haystack, $needle, $offset);