Merge branch '3.2/develop' of http://github.com/kohana/core into 3.2/develop
[kohana-core.git] / utf8 / strcspn.php
blob5951cb72ec21c99cb70ba02f7edac24279ced21e
1 <?php defined('SYSPATH') or die('No direct script access.');
2 /**
3 * UTF8::strcspn
5 * @package Kohana
6 * @author Kohana Team
7 * @copyright (c) 2007-2011 Kohana Team
8 * @copyright (c) 2005 Harry Fuecks
9 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
11 function _strcspn($str, $mask, $offset = NULL, $length = NULL)
13 if ($str == '' OR $mask == '')
14 return 0;
16 if (UTF8::is_ascii($str) AND UTF8::is_ascii($mask))
17 return ($offset === NULL) ? strcspn($str, $mask) : (($length === NULL) ? strcspn($str, $mask, $offset) : strcspn($str, $mask, $offset, $length));
19 if ($offset !== NULL OR $length !== NULL)
21 $str = UTF8::substr($str, $offset, $length);
24 // Escape these characters: - [ ] . : \ ^ /
25 // The . and : are escaped to prevent possible warnings about POSIX regex elements
26 $mask = preg_replace('#[-[\].:\\\\^/]#', '\\\\$0', $mask);
27 preg_match('/^[^'.$mask.']+/u', $str, $matches);
29 return isset($matches[0]) ? UTF8::strlen($matches[0]) : 0;