blob: 554d10040a9f2146603be91b7aa0117cc64ee514 [file] [log] [blame]
Andrey Andreev3fd1b382014-02-13 03:01:31 +02001<?php
2/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Andrey Andreev3fd1b382014-02-13 03:01:31 +02006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev3fd1b382014-02-13 03:01:31 +02008 *
Andrey Andreev125ef472016-01-11 12:33:00 +02009 * Copyright (c) 2014 - 2016, British Columbia Institute of Technology
Andrey Andreev3fd1b382014-02-13 03:01:31 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
Andrey Andreev3fd1b382014-02-13 03:01:31 +020017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * @package CodeIgniter
30 * @author EllisLab Dev Team
Andrey Andreev1924e872016-01-11 12:55:34 +020031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
Andrey Andreev125ef472016-01-11 12:33:00 +020032 * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
Andrey Andreevbd202c92016-01-11 12:50:18 +020034 * @link https://codeigniter.com
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020035 * @since Version 3.0.0
Andrey Andreev3fd1b382014-02-13 03:01:31 +020036 * @filesource
37 */
38defined('BASEPATH') OR exit('No direct script access allowed');
39
40/**
41 * PHP ext/mbstring compatibility package
42 *
43 * @package CodeIgniter
44 * @subpackage CodeIgniter
45 * @category Compatibility
46 * @author Andrey Andreev
Andrey Andreevbd202c92016-01-11 12:50:18 +020047 * @link https://codeigniter.com/user_guide/
Andrey Andreev3fd1b382014-02-13 03:01:31 +020048 * @link http://php.net/mbstring
49 */
50
51// ------------------------------------------------------------------------
52
53if (MB_ENABLED === TRUE)
54{
55 return;
56}
57
58// ------------------------------------------------------------------------
59
60if ( ! function_exists('mb_strlen'))
61{
62 /**
63 * mb_strlen()
64 *
65 * WARNING: This function WILL fall-back to strlen()
66 * if iconv is not available!
67 *
68 * @link http://php.net/mb_strlen
69 * @param string $str
70 * @param string $encoding
71 * @return string
72 */
73 function mb_strlen($str, $encoding = NULL)
74 {
75 if (ICONV_ENABLED === TRUE)
76 {
Andrey Andreevfd6efad2014-04-29 01:00:42 +030077 return iconv_strlen($str, isset($encoding) ? $encoding : config_item('charset'));
Andrey Andreev3fd1b382014-02-13 03:01:31 +020078 }
79
80 log_message('debug', 'Compatibility (mbstring): iconv_strlen() is not available, falling back to strlen().');
81 return strlen($str);
82 }
83}
84
85// ------------------------------------------------------------------------
86
87if ( ! function_exists('mb_strpos'))
88{
89 /**
90 * mb_strpos()
91 *
92 * WARNING: This function WILL fall-back to strpos()
93 * if iconv is not available!
94 *
bjjayb6d17462015-03-12 10:31:14 +080095 * @link http://php.net/mb_strpos
Andrey Andreev3fd1b382014-02-13 03:01:31 +020096 * @param string $haystack
97 * @param string $needle
98 * @param int $offset
99 * @param string $encoding
100 * @return mixed
101 */
102 function mb_strpos($haystack, $needle, $offset = 0, $encoding = NULL)
103 {
104 if (ICONV_ENABLED === TRUE)
105 {
106 return iconv_strpos($haystack, $needle, $offset, isset($encoding) ? $encoding : config_item('charset'));
107 }
108
109 log_message('debug', 'Compatibility (mbstring): iconv_strpos() is not available, falling back to strpos().');
110 return strpos($haystack, $needle, $offset);
111 }
112}
113
114// ------------------------------------------------------------------------
115
116if ( ! function_exists('mb_substr'))
117{
118 /**
119 * mb_substr()
120 *
121 * WARNING: This function WILL fall-back to substr()
122 * if iconv is not available.
123 *
124 * @link http://php.net/mb_substr
125 * @param string $str
126 * @param int $start
127 * @param int $length
128 * @param string $encoding
129 * @return string
130 */
131 function mb_substr($str, $start, $length = NULL, $encoding = NULL)
132 {
133 if (ICONV_ENABLED === TRUE)
134 {
135 isset($encoding) OR $encoding = config_item('charset');
136 return iconv_substr(
137 $str,
138 $start,
139 isset($length) ? $length : iconv_strlen($str, $encoding), // NULL doesn't work
140 $encoding
141 );
142 }
143
144 log_message('debug', 'Compatibility (mbstring): iconv_substr() is not available, falling back to substr().');
145 return isset($length)
146 ? substr($str, $start, $length)
147 : substr($str, $start);
148 }
149}