Skip to content
This repository
Browse code

Moving the mb_* functions to bootstrap.php

  • Loading branch information...
commit 3ee267d7ef5416912ce9b4982c5b2bd115a59a99 1 parent 1763f46
ADmad authored October 23, 2012
255  lib/Cake/I18n/Multibyte.php
@@ -18,261 +18,6 @@
18 18
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
19 19
  */
20 20
 
21  
-if (!function_exists('mb_stripos')) {
22  
-
23  
-/**
24  
- * Find position of first occurrence of a case-insensitive string.
25  
- *
26  
- * @param string $haystack The string from which to get the position of the first occurrence of $needle.
27  
- * @param string $needle The string to find in $haystack.
28  
- * @param integer $offset The position in $haystack to start searching.
29  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
30  
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false
31  
- *    if $needle is not found.
32  
- */
33  
-	function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
34  
-		return Multibyte::stripos($haystack, $needle, $offset);
35  
-	}
36  
-
37  
-}
38  
-
39  
-if (!function_exists('mb_stristr')) {
40  
-
41  
-/**
42  
- * Finds first occurrence of a string within another, case insensitive.
43  
- *
44  
- * @param string $haystack The string from which to get the first occurrence of $needle.
45  
- * @param string $needle The string to find in $haystack.
46  
- * @param boolean $part Determines which portion of $haystack this function returns.
47  
- *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
48  
- *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
49  
- *    Default value is false.
50  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
51  
- * @return string|boolean The portion of $haystack, or false if $needle is not found.
52  
- */
53  
-	function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
54  
-		return Multibyte::stristr($haystack, $needle, $part);
55  
-	}
56  
-
57  
-}
58  
-
59  
-if (!function_exists('mb_strlen')) {
60  
-
61  
-/**
62  
- * Get string length.
63  
- *
64  
- * @param string $string The string being checked for length.
65  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
66  
- * @return integer The number of characters in string $string having character encoding encoding.
67  
- *    A multi-byte character is counted as 1.
68  
- */
69  
-	function mb_strlen($string, $encoding = null) {
70  
-		return Multibyte::strlen($string);
71  
-	}
72  
-
73  
-}
74  
-
75  
-if (!function_exists('mb_strpos')) {
76  
-
77  
-/**
78  
- * Find position of first occurrence of a string.
79  
- *
80  
- * @param string $haystack The string being checked.
81  
- * @param string $needle The position counted from the beginning of haystack.
82  
- * @param integer $offset The search offset. If it is not specified, 0 is used.
83  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
84  
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
85  
- *    If $needle is not found, it returns false.
86  
- */
87  
-	function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
88  
-		return Multibyte::strpos($haystack, $needle, $offset);
89  
-	}
90  
-
91  
-}
92  
-
93  
-if (!function_exists('mb_strrchr')) {
94  
-
95  
-/**
96  
- * Finds the last occurrence of a character in a string within another.
97  
- *
98  
- * @param string $haystack The string from which to get the last occurrence of $needle.
99  
- * @param string $needle The string to find in $haystack.
100  
- * @param boolean $part Determines which portion of $haystack this function returns.
101  
- *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
102  
- *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
103  
- *    Default value is false.
104  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
105  
- * @return string|boolean The portion of $haystack. or false if $needle is not found.
106  
- */
107  
-	function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
108  
-		return Multibyte::strrchr($haystack, $needle, $part);
109  
-	}
110  
-
111  
-}
112  
-
113  
-if (!function_exists('mb_strrichr')) {
114  
-
115  
-/**
116  
- * Finds the last occurrence of a character in a string within another, case insensitive.
117  
- *
118  
- * @param string $haystack The string from which to get the last occurrence of $needle.
119  
- * @param string $needle The string to find in $haystack.
120  
- * @param boolean $part Determines which portion of $haystack this function returns.
121  
- *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
122  
- *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
123  
- *    Default value is false.
124  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
125  
- * @return string|boolean The portion of $haystack. or false if $needle is not found.
126  
- */
127  
-	function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
128  
-		return Multibyte::strrichr($haystack, $needle, $part);
129  
-	}
130  
-
131  
-}
132  
-
133  
-if (!function_exists('mb_strripos')) {
134  
-
135  
-/**
136  
- * Finds position of last occurrence of a string within another, case insensitive
137  
- *
138  
- * @param string $haystack The string from which to get the position of the last occurrence of $needle.
139  
- * @param string $needle The string to find in $haystack.
140  
- * @param integer $offset The position in $haystack to start searching.
141  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
142  
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
143  
- *    or false if $needle is not found.
144  
- */
145  
-	function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
146  
-		return Multibyte::strripos($haystack, $needle, $offset);
147  
-	}
148  
-
149  
-}
150  
-
151  
-if (!function_exists('mb_strrpos')) {
152  
-
153  
-/**
154  
- * Find position of last occurrence of a string in a string.
155  
- *
156  
- * @param string $haystack The string being checked, for the last occurrence of $needle.
157  
- * @param string $needle The string to find in $haystack.
158  
- * @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
159  
- *    Negative values will stop searching at an arbitrary point prior to the end of the string.
160  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
161  
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
162  
- *    If $needle is not found, it returns false.
163  
- */
164  
-	function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
165  
-		return Multibyte::strrpos($haystack, $needle, $offset);
166  
-	}
167  
-
168  
-}
169  
-
170  
-if (!function_exists('mb_strstr')) {
171  
-
172  
-/**
173  
- * Finds first occurrence of a string within another
174  
- *
175  
- * @param string $haystack The string from which to get the first occurrence of $needle.
176  
- * @param string $needle The string to find in $haystack
177  
- * @param boolean $part Determines which portion of $haystack this function returns.
178  
- *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
179  
- *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
180  
- *    Default value is FALSE.
181  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
182  
- * @return string|boolean The portion of $haystack, or true if $needle is not found.
183  
- */
184  
-	function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
185  
-		return Multibyte::strstr($haystack, $needle, $part);
186  
-	}
187  
-
188  
-}
189  
-
190  
-if (!function_exists('mb_strtolower')) {
191  
-
192  
-/**
193  
- * Make a string lowercase
194  
- *
195  
- * @param string $string The string being lowercased.
196  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
197  
- * @return string with all alphabetic characters converted to lowercase.
198  
- */
199  
-	function mb_strtolower($string, $encoding = null) {
200  
-		return Multibyte::strtolower($string);
201  
-	}
202  
-
203  
-}
204  
-
205  
-if (!function_exists('mb_strtoupper')) {
206  
-
207  
-/**
208  
- * Make a string uppercase
209  
- *
210  
- * @param string $string The string being uppercased.
211  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
212  
- * @return string with all alphabetic characters converted to uppercase.
213  
- */
214  
-	function mb_strtoupper($string, $encoding = null) {
215  
-		return Multibyte::strtoupper($string);
216  
-	}
217  
-
218  
-}
219  
-
220  
-if (!function_exists('mb_substr_count')) {
221  
-
222  
-/**
223  
- * Count the number of substring occurrences
224  
- *
225  
- * @param string $haystack The string being checked.
226  
- * @param string $needle The string being found.
227  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
228  
- * @return integer The number of times the $needle substring occurs in the $haystack string.
229  
- */
230  
-	function mb_substr_count($haystack, $needle, $encoding = null) {
231  
-		return Multibyte::substrCount($haystack, $needle);
232  
-	}
233  
-
234  
-}
235  
-
236  
-if (!function_exists('mb_substr')) {
237  
-
238  
-/**
239  
- * Get part of string
240  
- *
241  
- * @param string $string The string being checked.
242  
- * @param integer $start The first position used in $string.
243  
- * @param integer $length The maximum length of the returned string.
244  
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
245  
- * @return string The portion of $string specified by the $string and $length parameters.
246  
- */
247  
-	function mb_substr($string, $start, $length = null, $encoding = null) {
248  
-		return Multibyte::substr($string, $start, $length);
249  
-	}
250  
-
251  
-}
252  
-
253  
-if (!function_exists('mb_encode_mimeheader')) {
254  
-
255  
-/**
256  
- * Encode string for MIME header
257  
- *
258  
- * @param string $str The string being encoded
259  
- * @param string $charset specifies the name of the character set in which str is represented in.
260  
- *    The default value is determined by the current NLS setting (mbstring.language).
261  
- * @param string $transfer_encoding specifies the scheme of MIME encoding.
262  
- *    It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
263  
- * @param string $linefeed specifies the EOL (end-of-line) marker with which
264  
- *    mb_encode_mimeheader() performs line-folding
265  
- *    (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
266  
- *    The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
267  
- * @param integer $indent [definition unknown and appears to have no affect]
268  
- * @return string A converted version of the string represented in ASCII.
269  
- */
270  
-	function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
271  
-		return Multibyte::mimeEncode($str, $charset, $linefeed);
272  
-	}
273  
-
274  
-}
275  
-
276 21
 /**
277 22
  * Multibyte handling methods.
278 23
  *
257  lib/Cake/bootstrap.php
@@ -157,6 +157,7 @@
157 157
 App::uses('CakePlugin', 'Core');
158 158
 App::uses('Cache', 'Cache');
159 159
 App::uses('Object', 'Core');
  160
+App::uses('Multibyte', 'I18n');
160 161
 App::$bootstrapping = true;
161 162
 
162 163
 Configure::bootstrap(isset($boot) ? $boot : true);
@@ -167,3 +168,259 @@
167 168
 		mb_internal_encoding($encoding);
168 169
 	}
169 170
 }
  171
+
  172
+if (!function_exists('mb_stripos')) {
  173
+
  174
+/**
  175
+ * Find position of first occurrence of a case-insensitive string.
  176
+ *
  177
+ * @param string $haystack The string from which to get the position of the first occurrence of $needle.
  178
+ * @param string $needle The string to find in $haystack.
  179
+ * @param integer $offset The position in $haystack to start searching.
  180
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  181
+ * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false
  182
+ *    if $needle is not found.
  183
+ */
  184
+	function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
  185
+		return Multibyte::stripos($haystack, $needle, $offset);
  186
+	}
  187
+
  188
+}
  189
+
  190
+if (!function_exists('mb_stristr')) {
  191
+
  192
+/**
  193
+ * Finds first occurrence of a string within another, case insensitive.
  194
+ *
  195
+ * @param string $haystack The string from which to get the first occurrence of $needle.
  196
+ * @param string $needle The string to find in $haystack.
  197
+ * @param boolean $part Determines which portion of $haystack this function returns.
  198
+ *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  199
+ *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
  200
+ *    Default value is false.
  201
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  202
+ * @return string|boolean The portion of $haystack, or false if $needle is not found.
  203
+ */
  204
+	function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
  205
+		return Multibyte::stristr($haystack, $needle, $part);
  206
+	}
  207
+
  208
+}
  209
+
  210
+if (!function_exists('mb_strlen')) {
  211
+
  212
+/**
  213
+ * Get string length.
  214
+ *
  215
+ * @param string $string The string being checked for length.
  216
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  217
+ * @return integer The number of characters in string $string having character encoding encoding.
  218
+ *    A multi-byte character is counted as 1.
  219
+ */
  220
+	function mb_strlen($string, $encoding = null) {
  221
+		return Multibyte::strlen($string);
  222
+	}
  223
+
  224
+}
  225
+
  226
+if (!function_exists('mb_strpos')) {
  227
+
  228
+/**
  229
+ * Find position of first occurrence of a string.
  230
+ *
  231
+ * @param string $haystack The string being checked.
  232
+ * @param string $needle The position counted from the beginning of haystack.
  233
+ * @param integer $offset The search offset. If it is not specified, 0 is used.
  234
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  235
+ * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
  236
+ *    If $needle is not found, it returns false.
  237
+ */
  238
+	function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
  239
+		return Multibyte::strpos($haystack, $needle, $offset);
  240
+	}
  241
+
  242
+}
  243
+
  244
+if (!function_exists('mb_strrchr')) {
  245
+
  246
+/**
  247
+ * Finds the last occurrence of a character in a string within another.
  248
+ *
  249
+ * @param string $haystack The string from which to get the last occurrence of $needle.
  250
+ * @param string $needle The string to find in $haystack.
  251
+ * @param boolean $part Determines which portion of $haystack this function returns.
  252
+ *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  253
+ *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
  254
+ *    Default value is false.
  255
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  256
+ * @return string|boolean The portion of $haystack. or false if $needle is not found.
  257
+ */
  258
+	function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
  259
+		return Multibyte::strrchr($haystack, $needle, $part);
  260
+	}
  261
+
  262
+}
  263
+
  264
+if (!function_exists('mb_strrichr')) {
  265
+
  266
+/**
  267
+ * Finds the last occurrence of a character in a string within another, case insensitive.
  268
+ *
  269
+ * @param string $haystack The string from which to get the last occurrence of $needle.
  270
+ * @param string $needle The string to find in $haystack.
  271
+ * @param boolean $part Determines which portion of $haystack this function returns.
  272
+ *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  273
+ *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
  274
+ *    Default value is false.
  275
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  276
+ * @return string|boolean The portion of $haystack. or false if $needle is not found.
  277
+ */
  278
+	function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
  279
+		return Multibyte::strrichr($haystack, $needle, $part);
  280
+	}
  281
+
  282
+}
  283
+
  284
+if (!function_exists('mb_strripos')) {
  285
+
  286
+/**
  287
+ * Finds position of last occurrence of a string within another, case insensitive
  288
+ *
  289
+ * @param string $haystack The string from which to get the position of the last occurrence of $needle.
  290
+ * @param string $needle The string to find in $haystack.
  291
+ * @param integer $offset The position in $haystack to start searching.
  292
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  293
+ * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
  294
+ *    or false if $needle is not found.
  295
+ */
  296
+	function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
  297
+		return Multibyte::strripos($haystack, $needle, $offset);
  298
+	}
  299
+
  300
+}
  301
+
  302
+if (!function_exists('mb_strrpos')) {
  303
+
  304
+/**
  305
+ * Find position of last occurrence of a string in a string.
  306
+ *
  307
+ * @param string $haystack The string being checked, for the last occurrence of $needle.
  308
+ * @param string $needle The string to find in $haystack.
  309
+ * @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
  310
+ *    Negative values will stop searching at an arbitrary point prior to the end of the string.
  311
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  312
+ * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
  313
+ *    If $needle is not found, it returns false.
  314
+ */
  315
+	function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
  316
+		return Multibyte::strrpos($haystack, $needle, $offset);
  317
+	}
  318
+
  319
+}
  320
+
  321
+if (!function_exists('mb_strstr')) {
  322
+
  323
+/**
  324
+ * Finds first occurrence of a string within another
  325
+ *
  326
+ * @param string $haystack The string from which to get the first occurrence of $needle.
  327
+ * @param string $needle The string to find in $haystack
  328
+ * @param boolean $part Determines which portion of $haystack this function returns.
  329
+ *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  330
+ *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
  331
+ *    Default value is FALSE.
  332
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  333
+ * @return string|boolean The portion of $haystack, or true if $needle is not found.
  334
+ */
  335
+	function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
  336
+		return Multibyte::strstr($haystack, $needle, $part);
  337
+	}
  338
+
  339
+}
  340
+
  341
+if (!function_exists('mb_strtolower')) {
  342
+
  343
+/**
  344
+ * Make a string lowercase
  345
+ *
  346
+ * @param string $string The string being lowercased.
  347
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  348
+ * @return string with all alphabetic characters converted to lowercase.
  349
+ */
  350
+	function mb_strtolower($string, $encoding = null) {
  351
+		return Multibyte::strtolower($string);
  352
+	}
  353
+
  354
+}
  355
+
  356
+if (!function_exists('mb_strtoupper')) {
  357
+
  358
+/**
  359
+ * Make a string uppercase
  360
+ *
  361
+ * @param string $string The string being uppercased.
  362
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  363
+ * @return string with all alphabetic characters converted to uppercase.
  364
+ */
  365
+	function mb_strtoupper($string, $encoding = null) {
  366
+		return Multibyte::strtoupper($string);
  367
+	}
  368
+
  369
+}
  370
+
  371
+if (!function_exists('mb_substr_count')) {
  372
+
  373
+/**
  374
+ * Count the number of substring occurrences
  375
+ *
  376
+ * @param string $haystack The string being checked.
  377
+ * @param string $needle The string being found.
  378
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  379
+ * @return integer The number of times the $needle substring occurs in the $haystack string.
  380
+ */
  381
+	function mb_substr_count($haystack, $needle, $encoding = null) {
  382
+		return Multibyte::substrCount($haystack, $needle);
  383
+	}
  384
+
  385
+}
  386
+
  387
+if (!function_exists('mb_substr')) {
  388
+
  389
+/**
  390
+ * Get part of string
  391
+ *
  392
+ * @param string $string The string being checked.
  393
+ * @param integer $start The first position used in $string.
  394
+ * @param integer $length The maximum length of the returned string.
  395
+ * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  396
+ * @return string The portion of $string specified by the $string and $length parameters.
  397
+ */
  398
+	function mb_substr($string, $start, $length = null, $encoding = null) {
  399
+		return Multibyte::substr($string, $start, $length);
  400
+	}
  401
+
  402
+}
  403
+
  404
+if (!function_exists('mb_encode_mimeheader')) {
  405
+
  406
+/**
  407
+ * Encode string for MIME header
  408
+ *
  409
+ * @param string $str The string being encoded
  410
+ * @param string $charset specifies the name of the character set in which str is represented in.
  411
+ *    The default value is determined by the current NLS setting (mbstring.language).
  412
+ * @param string $transfer_encoding specifies the scheme of MIME encoding.
  413
+ *    It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
  414
+ * @param string $linefeed specifies the EOL (end-of-line) marker with which
  415
+ *    mb_encode_mimeheader() performs line-folding
  416
+ *    (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
  417
+ *    The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
  418
+ * @param integer $indent [definition unknown and appears to have no affect]
  419
+ * @return string A converted version of the string represented in ASCII.
  420
+ */
  421
+	function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
  422
+		return Multibyte::mimeEncode($str, $charset, $linefeed);
  423
+	}
  424
+
  425
+}
  426
+

0 notes on commit 3ee267d

Please sign in to comment.
Something went wrong with that request. Please try again.