Esempio n. 1
2
/**
 * utf8::str_pad
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
    if (utf8::is_ascii($str) and utf8::is_ascii($pad_str)) {
        return str_pad($str, $final_str_length, $pad_str, $pad_type);
    }
    $str_length = utf8::strlen($str);
    if ($final_str_length <= 0 or $final_str_length <= $str_length) {
        return $str;
    }
    $pad_str_length = utf8::strlen($pad_str);
    $pad_length = $final_str_length - $str_length;
    if ($pad_type == STR_PAD_RIGHT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
    }
    if ($pad_type == STR_PAD_LEFT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
    }
    if ($pad_type == STR_PAD_BOTH) {
        $pad_length /= 2;
        $pad_length_left = floor($pad_length);
        $pad_length_right = ceil($pad_length);
        $repeat_left = ceil($pad_length_left / $pad_str_length);
        $repeat_right = ceil($pad_length_right / $pad_str_length);
        $pad_left = utf8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
        $pad_right = utf8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_left);
        return $pad_left . $str . $pad_right;
    }
    trigger_error('utf8::str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR);
}
Esempio n. 2
0
/**
 * utf8::strlen
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strlen($str)
{
    if (utf8::is_ascii($str)) {
        return strlen($str);
    }
    return strlen(utf8_decode($str));
}
Esempio n. 3
0
/**
 * utf8::strrev
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strrev($str)
{
    if (utf8::is_ascii($str)) {
        return strrev($str);
    }
    preg_match_all('/./us', $str, $matches);
    return implode('', array_reverse($matches[0]));
}
/**
 * utf8::ucfirst
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _ucfirst($str)
{
    if (utf8::is_ascii($str)) {
        return ucfirst($str);
    }
    preg_match('/^(.?)(.*)$/us', $str, $matches);
    return utf8::strtoupper($matches[1]) . $matches[2];
}
Esempio n. 5
0
/**
 * utf8::strcasecmp
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strcasecmp($str1, $str2)
{
    if (utf8::is_ascii($str1) and utf8::is_ascii($str2)) {
        return strcasecmp($str1, $str2);
    }
    $str1 = utf8::strtolower($str1);
    $str2 = utf8::strtolower($str2);
    return strcmp($str1, $str2);
}
Esempio n. 6
0
/**
 * utf8::ucwords
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _ucwords($str)
{
    if (utf8::is_ascii($str)) {
        return ucwords($str);
    }
    // [\x0c\x09\x0b\x0a\x0d\x20] matches form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns.
    // This corresponds to the definition of a 'word' defined at http://php.net/ucwords
    return preg_replace('/(?<=^|[\\x0c\\x09\\x0b\\x0a\\x0d\\x20])[^\\x0c\\x09\\x0b\\x0a\\x0d\\x20]/ue', 'utf8::strtoupper(\'$0\')', $str);
}
Esempio n. 7
0
/**
 * utf8::strlen
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strlen($str)
{
    // Try mb_strlen() first because it's faster than combination of is_ascii() and strlen()
    if (SERVER_UTF8) {
        return mb_strlen($str);
    }
    if (utf8::is_ascii($str)) {
        return strlen($str);
    }
    return strlen(utf8_decode($str));
}
Esempio n. 8
0
/**
 * utf8::substr_replace
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _substr_replace($str, $replacement, $offset, $length = NULL)
{
    if (utf8::is_ascii($str)) {
        return $length === NULL ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length);
    }
    $length = $length === NULL ? utf8::strlen($str) : (int) $length;
    preg_match_all('/./us', $str, $str_array);
    preg_match_all('/./us', $replacement, $replacement_array);
    array_splice($str_array[0], $offset, $length, $replacement_array[0]);
    return implode('', $str_array[0]);
}
Esempio n. 9
0
/**
 * utf8::substr
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _substr($str, $offset, $length = NULL)
{
    if (SERVER_UTF8) {
        return $length === NULL ? mb_substr($str, $offset) : mb_substr($str, $offset, $length);
    }
    if (utf8::is_ascii($str)) {
        return $length === NULL ? substr($str, $offset) : substr($str, $offset, $length);
    }
    // Normalize params
    $str = (string) $str;
    $strlen = utf8::strlen($str);
    $offset = (int) ($offset < 0) ? max(0, $strlen + $offset) : $offset;
    // Normalize to positive offset
    $length = $length === NULL ? NULL : (int) $length;
    // Impossible
    if ($length === 0 or $offset >= $strlen or $length < 0 and $length <= $offset - $strlen) {
        return '';
    }
    // Whole string
    if ($offset == 0 and ($length === NULL or $length >= $strlen)) {
        return $str;
    }
    // Build regex
    $regex = '^';
    // Create an offset expression
    if ($offset > 0) {
        // PCRE repeating quantifiers must be less than 65536, so repeat when necessary
        $x = (int) ($offset / 65535);
        $y = (int) ($offset % 65535);
        $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
        $regex .= $y == 0 ? '' : '.{' . $y . '}';
    }
    // Create a length expression
    if ($length === NULL) {
        $regex .= '(.*)';
        // No length set, grab it all
    } elseif ($length > 0) {
        // Reduce length so that it can't go beyond the end of the string
        $length = min($strlen - $offset, $length);
        $x = (int) ($length / 65535);
        $y = (int) ($length % 65535);
        $regex .= '(';
        $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
        $regex .= '.{' . $y . '})';
    } else {
        $x = (int) (-$length / 65535);
        $y = (int) (-$length % 65535);
        $regex .= '(.*)';
        $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
        $regex .= '.{' . $y . '}';
    }
    preg_match('/' . $regex . '/us', $str, $matches);
    return $matches[1];
}
Esempio n. 10
0
/**
 * utf8::rtrim
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _rtrim($str, $charlist = NULL)
{
    if ($charlist === NULL) {
        return rtrim($str);
    }
    if (utf8::is_ascii($charlist)) {
        return rtrim($str, $charlist);
    }
    $charlist = preg_replace('#[-\\[\\]:\\\\^/]#', '\\\\$0', $charlist);
    return preg_replace('/[' . $charlist . ']++$/uD', '', $str);
}
Esempio n. 11
0
/**
 * utf8::strrpos
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strrpos($str, $search, $offset = 0)
{
    $offset = (int) $offset;
    if (utf8::is_ascii($str) and utf8::is_ascii($search)) {
        return strrpos($str, $search, $offset);
    }
    if ($offset == 0) {
        $array = explode($search, $str, -1);
        return isset($array[0]) ? utf8::strlen(implode($search, $array)) : FALSE;
    }
    $str = utf8::substr($str, $offset);
    $pos = utf8::strrpos($str, $search);
    return $pos === FALSE ? FALSE : $pos + $offset;
}
Esempio n. 12
0
/**
 * utf8::str_split
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_split($str, $split_length = 1)
{
    $split_length = (int) $split_length;
    if (utf8::is_ascii($str)) {
        return str_split($str, $split_length);
    }
    if ($split_length < 1) {
        return FALSE;
    }
    if (utf8::strlen($str) <= $split_length) {
        return array($str);
    }
    preg_match_all('/.{' . $split_length . '}|[^\\x00]{1,' . $split_length . '}$/us', $str, $matches);
    return $matches[0];
}
Esempio n. 13
0
/**
 * utf8::stristr
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _stristr($str, $search)
{
    if (utf8::is_ascii($str) and utf8::is_ascii($search)) {
        return stristr($str, $search);
    }
    if ($search == '') {
        return $str;
    }
    $str_lower = utf8::strtolower($str);
    $search_lower = utf8::strtolower($search);
    preg_match('/^(.*?)' . preg_quote($search, '/') . '/s', $str_lower, $matches);
    if (isset($matches[1])) {
        return substr($str, strlen($matches[1]));
    }
    return FALSE;
}
Esempio n. 14
0
/**
 * utf8::strcspn
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strcspn($str, $mask, $offset = NULL, $length = NULL)
{
    if ($str == '' or $mask == '') {
        return 0;
    }
    if (utf8::is_ascii($str) and utf8::is_ascii($mask)) {
        return $offset === NULL ? strcspn($str, $mask) : ($length === NULL ? strcspn($str, $mask, $offset) : strcspn($str, $mask, $offset, $length));
    }
    if ($start !== NULL or $length !== NULL) {
        $str = utf8::substr($str, $offset, $length);
    }
    // Escape these characters:  - [ ] . : \ ^ /
    // The . and : are escaped to prevent possible warnings about POSIX regex elements
    $mask = preg_replace('#[-[\\].:\\\\^/]#', '\\\\$0', $mask);
    preg_match('/^[^' . $mask . ']+/u', $str, $matches);
    return isset($matches[0]) ? utf8::strlen($matches[0]) : 0;
}
Esempio n. 15
0
/**
 * utf8::strtoupper
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strtoupper($str)
{
    if (utf8::is_ascii($str)) {
        return strtoupper($str);
    }
    static $UTF8_LOWER_TO_UPPER = NULL;
    if ($UTF8_LOWER_TO_UPPER === NULL) {
        $UTF8_LOWER_TO_UPPER = array(0x61 => 0x41, 0x3c6 => 0x3a6, 0x163 => 0x162, 0xe5 => 0xc5, 0x62 => 0x42, 0x13a => 0x139, 0xe1 => 0xc1, 0x142 => 0x141, 0x3cd => 0x38e, 0x101 => 0x100, 0x491 => 0x490, 0x3b4 => 0x394, 0x15b => 0x15a, 0x64 => 0x44, 0x3b3 => 0x393, 0xf4 => 0xd4, 0x44a => 0x42a, 0x439 => 0x419, 0x113 => 0x112, 0x43c => 0x41c, 0x15f => 0x15e, 0x144 => 0x143, 0xee => 0xce, 0x45e => 0x40e, 0x44f => 0x42f, 0x3ba => 0x39a, 0x155 => 0x154, 0x69 => 0x49, 0x73 => 0x53, 0x1e1f => 0x1e1e, 0x135 => 0x134, 0x447 => 0x427, 0x3c0 => 0x3a0, 0x438 => 0x418, 0xf3 => 0xd3, 0x440 => 0x420, 0x454 => 0x404, 0x435 => 0x415, 0x449 => 0x429, 0x14b => 0x14a, 0x431 => 0x411, 0x459 => 0x409, 0x1e03 => 0x1e02, 0xf6 => 0xd6, 0xf9 => 0xd9, 0x6e => 0x4e, 0x451 => 0x401, 0x3c4 => 0x3a4, 0x443 => 0x423, 0x15d => 0x15c, 0x453 => 0x403, 0x3c8 => 0x3a8, 0x159 => 0x158, 0x67 => 0x47, 0xe4 => 0xc4, 0x3ac => 0x386, 0x3ae => 0x389, 0x167 => 0x166, 0x3be => 0x39e, 0x165 => 0x164, 0x117 => 0x116, 0x109 => 0x108, 0x76 => 0x56, 0xfe => 0xde, 0x157 => 0x156, 0xfa => 0xda, 0x1e61 => 0x1e60, 0x1e83 => 0x1e82, 0xe2 => 0xc2, 0x119 => 0x118, 0x146 => 0x145, 0x70 => 0x50, 0x151 => 0x150, 0x44e => 0x42e, 0x129 => 0x128, 0x3c7 => 0x3a7, 0x13e => 0x13d, 0x442 => 0x422, 0x7a => 0x5a, 0x448 => 0x428, 0x3c1 => 0x3a1, 0x1e81 => 0x1e80, 0x16d => 0x16c, 0xf5 => 0xd5, 0x75 => 0x55, 0x177 => 0x176, 0xfc => 0xdc, 0x1e57 => 0x1e56, 0x3c3 => 0x3a3, 0x43a => 0x41a, 0x6d => 0x4d, 0x16b => 0x16a, 0x171 => 0x170, 0x444 => 0x424, 0xec => 0xcc, 0x169 => 0x168, 0x3bf => 0x39f, 0x6b => 0x4b, 0xf2 => 0xd2, 0xe0 => 0xc0, 0x434 => 0x414, 0x3c9 => 0x3a9, 0x1e6b => 0x1e6a, 0xe3 => 0xc3, 0x44d => 0x42d, 0x436 => 0x416, 0x1a1 => 0x1a0, 0x10d => 0x10c, 0x11d => 0x11c, 0xf0 => 0xd0, 0x13c => 0x13b, 0x45f => 0x40f, 0x45a => 0x40a, 0xe8 => 0xc8, 0x3c5 => 0x3a5, 0x66 => 0x46, 0xfd => 0xdd, 0x63 => 0x43, 0x21b => 0x21a, 0xea => 0xca, 0x3b9 => 0x399, 0x17a => 0x179, 0xef => 0xcf, 0x1b0 => 0x1af, 0x65 => 0x45, 0x3bb => 0x39b, 0x3b8 => 0x398, 0x3bc => 0x39c, 0x45c => 0x40c, 0x43f => 0x41f, 0x44c => 0x42c, 0xfe => 0xde, 0xf0 => 0xd0, 0x1ef3 => 0x1ef2, 0x68 => 0x48, 0xeb => 0xcb, 0x111 => 0x110, 0x433 => 0x413, 0x12f => 0x12e, 0xe6 => 0xc6, 0x78 => 0x58, 0x161 => 0x160, 0x16f => 0x16e, 0x3b1 => 0x391, 0x457 => 0x407, 0x173 => 0x172, 0xff => 0x178, 0x6f => 0x4f, 0x43b => 0x41b, 0x3b5 => 0x395, 0x445 => 0x425, 0x121 => 0x120, 0x17e => 0x17d, 0x17c => 0x17b, 0x3b6 => 0x396, 0x3b2 => 0x392, 0x3ad => 0x388, 0x1e85 => 0x1e84, 0x175 => 0x174, 0x71 => 0x51, 0x437 => 0x417, 0x1e0b => 0x1e0a, 0x148 => 0x147, 0x105 => 0x104, 0x458 => 0x408, 0x14d => 0x14c, 0xed => 0xcd, 0x79 => 0x59, 0x10b => 0x10a, 0x3ce => 0x38f, 0x72 => 0x52, 0x430 => 0x410, 0x455 => 0x405, 0x452 => 0x402, 0x127 => 0x126, 0x137 => 0x136, 0x12b => 0x12a, 0x3af => 0x38a, 0x44b => 0x42b, 0x6c => 0x4c, 0x3b7 => 0x397, 0x125 => 0x124, 0x219 => 0x218, 0xfb => 0xdb, 0x11f => 0x11e, 0x43e => 0x41e, 0x1e41 => 0x1e40, 0x3bd => 0x39d, 0x107 => 0x106, 0x3cb => 0x3ab, 0x446 => 0x426, 0xfe => 0xde, 0xe7 => 0xc7, 0x3ca => 0x3aa, 0x441 => 0x421, 0x432 => 0x412, 0x10f => 0x10e, 0xf8 => 0xd8, 0x77 => 0x57, 0x11b => 0x11a, 0x74 => 0x54, 0x6a => 0x4a, 0x45b => 0x40b, 0x456 => 0x406, 0x103 => 0x102, 0x3bb => 0x39b, 0xf1 => 0xd1, 0x43d => 0x41d, 0x3cc => 0x38c, 0xe9 => 0xc9, 0xf0 => 0xd0, 0x457 => 0x407, 0x123 => 0x122);
    }
    $uni = utf8::to_unicode($str);
    if ($uni === FALSE) {
        return FALSE;
    }
    for ($i = 0, $c = count($uni); $i < $c; $i++) {
        if (isset($UTF8_LOWER_TO_UPPER[$uni[$i]])) {
            $uni[$i] = $UTF8_LOWER_TO_UPPER[$uni[$i]];
        }
    }
    return utf8::from_unicode($uni);
}
Esempio n. 16
0
/**
 * utf8::strtolower
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strtolower($str)
{
    if (utf8::is_ascii($str)) {
        return strtolower($str);
    }
    static $UTF8_UPPER_TO_LOWER = NULL;
    if ($UTF8_UPPER_TO_LOWER === NULL) {
        $UTF8_UPPER_TO_LOWER = array(0x41 => 0x61, 0x3a6 => 0x3c6, 0x162 => 0x163, 0xc5 => 0xe5, 0x42 => 0x62, 0x139 => 0x13a, 0xc1 => 0xe1, 0x141 => 0x142, 0x38e => 0x3cd, 0x100 => 0x101, 0x490 => 0x491, 0x394 => 0x3b4, 0x15a => 0x15b, 0x44 => 0x64, 0x393 => 0x3b3, 0xd4 => 0xf4, 0x42a => 0x44a, 0x419 => 0x439, 0x112 => 0x113, 0x41c => 0x43c, 0x15e => 0x15f, 0x143 => 0x144, 0xce => 0xee, 0x40e => 0x45e, 0x42f => 0x44f, 0x39a => 0x3ba, 0x154 => 0x155, 0x49 => 0x69, 0x53 => 0x73, 0x1e1e => 0x1e1f, 0x134 => 0x135, 0x427 => 0x447, 0x3a0 => 0x3c0, 0x418 => 0x438, 0xd3 => 0xf3, 0x420 => 0x440, 0x404 => 0x454, 0x415 => 0x435, 0x429 => 0x449, 0x14a => 0x14b, 0x411 => 0x431, 0x409 => 0x459, 0x1e02 => 0x1e03, 0xd6 => 0xf6, 0xd9 => 0xf9, 0x4e => 0x6e, 0x401 => 0x451, 0x3a4 => 0x3c4, 0x423 => 0x443, 0x15c => 0x15d, 0x403 => 0x453, 0x3a8 => 0x3c8, 0x158 => 0x159, 0x47 => 0x67, 0xc4 => 0xe4, 0x386 => 0x3ac, 0x389 => 0x3ae, 0x166 => 0x167, 0x39e => 0x3be, 0x164 => 0x165, 0x116 => 0x117, 0x108 => 0x109, 0x56 => 0x76, 0xde => 0xfe, 0x156 => 0x157, 0xda => 0xfa, 0x1e60 => 0x1e61, 0x1e82 => 0x1e83, 0xc2 => 0xe2, 0x118 => 0x119, 0x145 => 0x146, 0x50 => 0x70, 0x150 => 0x151, 0x42e => 0x44e, 0x128 => 0x129, 0x3a7 => 0x3c7, 0x13d => 0x13e, 0x422 => 0x442, 0x5a => 0x7a, 0x428 => 0x448, 0x3a1 => 0x3c1, 0x1e80 => 0x1e81, 0x16c => 0x16d, 0xd5 => 0xf5, 0x55 => 0x75, 0x176 => 0x177, 0xdc => 0xfc, 0x1e56 => 0x1e57, 0x3a3 => 0x3c3, 0x41a => 0x43a, 0x4d => 0x6d, 0x16a => 0x16b, 0x170 => 0x171, 0x424 => 0x444, 0xcc => 0xec, 0x168 => 0x169, 0x39f => 0x3bf, 0x4b => 0x6b, 0xd2 => 0xf2, 0xc0 => 0xe0, 0x414 => 0x434, 0x3a9 => 0x3c9, 0x1e6a => 0x1e6b, 0xc3 => 0xe3, 0x42d => 0x44d, 0x416 => 0x436, 0x1a0 => 0x1a1, 0x10c => 0x10d, 0x11c => 0x11d, 0xd0 => 0xf0, 0x13b => 0x13c, 0x40f => 0x45f, 0x40a => 0x45a, 0xc8 => 0xe8, 0x3a5 => 0x3c5, 0x46 => 0x66, 0xdd => 0xfd, 0x43 => 0x63, 0x21a => 0x21b, 0xca => 0xea, 0x399 => 0x3b9, 0x179 => 0x17a, 0xcf => 0xef, 0x1af => 0x1b0, 0x45 => 0x65, 0x39b => 0x3bb, 0x398 => 0x3b8, 0x39c => 0x3bc, 0x40c => 0x45c, 0x41f => 0x43f, 0x42c => 0x44c, 0xde => 0xfe, 0xd0 => 0xf0, 0x1ef2 => 0x1ef3, 0x48 => 0x68, 0xcb => 0xeb, 0x110 => 0x111, 0x413 => 0x433, 0x12e => 0x12f, 0xc6 => 0xe6, 0x58 => 0x78, 0x160 => 0x161, 0x16e => 0x16f, 0x391 => 0x3b1, 0x407 => 0x457, 0x172 => 0x173, 0x178 => 0xff, 0x4f => 0x6f, 0x41b => 0x43b, 0x395 => 0x3b5, 0x425 => 0x445, 0x120 => 0x121, 0x17d => 0x17e, 0x17b => 0x17c, 0x396 => 0x3b6, 0x392 => 0x3b2, 0x388 => 0x3ad, 0x1e84 => 0x1e85, 0x174 => 0x175, 0x51 => 0x71, 0x417 => 0x437, 0x1e0a => 0x1e0b, 0x147 => 0x148, 0x104 => 0x105, 0x408 => 0x458, 0x14c => 0x14d, 0xcd => 0xed, 0x59 => 0x79, 0x10a => 0x10b, 0x38f => 0x3ce, 0x52 => 0x72, 0x410 => 0x430, 0x405 => 0x455, 0x402 => 0x452, 0x126 => 0x127, 0x136 => 0x137, 0x12a => 0x12b, 0x38a => 0x3af, 0x42b => 0x44b, 0x4c => 0x6c, 0x397 => 0x3b7, 0x124 => 0x125, 0x218 => 0x219, 0xdb => 0xfb, 0x11e => 0x11f, 0x41e => 0x43e, 0x1e40 => 0x1e41, 0x39d => 0x3bd, 0x106 => 0x107, 0x3ab => 0x3cb, 0x426 => 0x446, 0xde => 0xfe, 0xc7 => 0xe7, 0x3aa => 0x3ca, 0x421 => 0x441, 0x412 => 0x432, 0x10e => 0x10f, 0xd8 => 0xf8, 0x57 => 0x77, 0x11a => 0x11b, 0x54 => 0x74, 0x4a => 0x6a, 0x40b => 0x45b, 0x406 => 0x456, 0x102 => 0x103, 0x39b => 0x3bb, 0xd1 => 0xf1, 0x41d => 0x43d, 0x38c => 0x3cc, 0xc9 => 0xe9, 0xd0 => 0xf0, 0x407 => 0x457, 0x122 => 0x123);
    }
    $uni = utf8::to_unicode($str);
    if ($uni === FALSE) {
        return FALSE;
    }
    for ($i = 0, $c = count($uni); $i < $c; $i++) {
        if (isset($UTF8_UPPER_TO_LOWER[$uni[$i]])) {
            $uni[$i] = $UTF8_UPPER_TO_LOWER[$uni[$i]];
        }
    }
    return utf8::from_unicode($uni);
}
Esempio n. 17
0
/**
 * utf8::str_ireplace
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_ireplace($search, $replace, $str, &$count = NULL)
{
    if (utf8::is_ascii($search) and utf8::is_ascii($replace) and utf8::is_ascii($str)) {
        return str_ireplace($search, $replace, $str, $count);
    }
    if (is_array($str)) {
        foreach ($str as $key => $val) {
            $str[$key] = utf8::str_ireplace($search, $replace, $val, $count);
        }
        return $str;
    }
    if (is_array($search)) {
        $keys = array_keys($search);
        foreach ($keys as $k) {
            if (is_array($replace)) {
                if (array_key_exists($k, $replace)) {
                    $str = utf8::str_ireplace($search[$k], $replace[$k], $str, $count);
                } else {
                    $str = utf8::str_ireplace($search[$k], '', $str, $count);
                }
            } else {
                $str = utf8::str_ireplace($search[$k], $replace, $str, $count);
            }
        }
        return $str;
    }
    $search = utf8::strtolower($search);
    $str_lower = utf8::strtolower($str);
    $total_matched_strlen = 0;
    $i = 0;
    while (preg_match('/(.*?)' . preg_quote($search, '/') . '/s', $str_lower, $matches)) {
        $matched_strlen = strlen($matches[0]);
        $str_lower = substr($str_lower, $matched_strlen);
        $offset = $total_matched_strlen + strlen($matches[1]) + $i * (strlen($replace) - 1);
        $str = substr_replace($str, $replace, $offset, strlen($search));
        $total_matched_strlen += $matched_strlen;
        $i++;
    }
    $count += $i;
    return $str;
}
Esempio n. 18
0
 /**
  * execute all sql srips from the upgrade folder
  *
  * @param string $baseDir directory to the module folder updgrades are in.
  * @param string $upgrade_folder folder version name
  */
 public function execute_sql_scripts($baseDir, $upgrade_folder, $appName, &$last_run_script)
 {
     $file_name = array();
     $full_upgrade_folder = $baseDir . "db/" . $upgrade_folder;
     // get last executed sql file name. If not in the parameter (which loads from the db via the
     // system model), then it could be from an old version of Indicia pre 0.8 so has the last
     // run script saved as a file in the db scripts folder. Or we could just be starting a new folder.
     if (empty($last_run_script)) {
         $last_run_script = $this->get_last_executed_sql_file_name($full_upgrade_folder, $appName);
     }
     $original_last_run_script = $last_run_script;
     if (($handle = @opendir($full_upgrade_folder)) != FALSE) {
         while (($file = readdir($handle)) != false) {
             if (!preg_match("/^20.*\\.sql\$/", $file)) {
                 continue;
             }
             $file_name[] = $file;
         }
         @closedir($handle);
     } else {
         throw new Exception("Cant open dir " . $full_upgrade_folder);
     }
     sort($file_name);
     try {
         foreach ($file_name as $name) {
             if (strcmp($name, $last_run_script) > 0 || empty($last_run_script)) {
                 if (false === ($_db_file = file_get_contents($full_upgrade_folder . '/' . $name))) {
                     throw new Exception("Can't open file " . $full_upgrade_folder . '/' . $name);
                 }
                 kohana::log('debug', "Upgrading file {$name}");
                 // @todo Look into why utf8 files do not run without conversion to ascii.
                 if (!utf8::is_ascii($_db_file)) {
                     $_db_file = utf8::strip_non_ascii($_db_file);
                 }
                 if (substr($_db_file, 0, 18) === '-- #postgres user#') {
                     $this->scriptsForPgUser .= $_db_file . "\n\n";
                 } elseif (substr($_db_file, 0, 16) === '-- #slow script#' && $this->couldBeSlow) {
                     $this->slowScripts .= $_db_file . "\n\n";
                 } else {
                     $result = $this->db->query($_db_file);
                 }
                 $last_run_script = $name;
             }
         }
     } catch (Exception $e) {
         kohana::log('error', "Error in file: " . $full_upgrade_folder . '/' . $name);
         kohana::log('error', $e->getMessage());
         throw $e;
     }
     $this->update_last_executed_sql_file($full_upgrade_folder, $appName, $original_last_run_script, $last_run_script);
     return true;
 }
Esempio n. 19
0
File: text.php Progetto: Toushi/flow
 /**
  * Generates a random string of a given type and length.
  *
  * @param   string   a type of pool, or a string of characters to use as the pool
  * @param   integer  length of string to return
  * @return  string
  *
  * @tutorial  alnum    - alpha-numeric characters
  * @tutorial  alpha    - alphabetical characters
  * @tutorial  numeric  - digit characters, 0-9
  * @tutorial  nozero   - digit characters, 1-9
  * @tutorial  distinct - clearly distinct alpha-numeric characters
  */
 public static function random($type = 'alnum', $length = 8)
 {
     $utf8 = FALSE;
     switch ($type) {
         case 'alnum':
             $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
         case 'alpha':
             $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
         case 'numeric':
             $pool = '0123456789';
             break;
         case 'nozero':
             $pool = '123456789';
             break;
         case 'distinct':
             $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
             break;
         default:
             $pool = (string) $type;
             $utf8 = !utf8::is_ascii($pool);
             break;
     }
     $str = '';
     $pool_size = $utf8 === TRUE ? utf8::strlen($pool) : strlen($pool);
     for ($i = 0; $i < $length; $i++) {
         $str .= $utf8 === TRUE ? utf8::substr($pool, mt_rand(0, $pool_size - 1), 1) : substr($pool, mt_rand(0, $pool_size - 1), 1);
     }
     return $str;
 }
Esempio n. 20
0
 /**
  * Generates a random string of a given type and length.
  *
  * @param   string   a type of pool, or a string of characters to use as the pool
  * @param   integer  length of string to return
  * @return  string
  *
  * @tutorial  alnum     alpha-numeric characters
  * @tutorial  alpha     alphabetical characters
  * @tutorial  hexdec    hexadecimal characters, 0-9 plus a-f
  * @tutorial  numeric   digit characters, 0-9
  * @tutorial  nozero    digit characters, 1-9
  * @tutorial  distinct  clearly distinct alpha-numeric characters
  */
 public static function random($type = 'alnum', $length = 8)
 {
     $utf8 = FALSE;
     switch ($type) {
         case 'alnum':
             $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
         case 'alpha':
             $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
         case 'hexdec':
             $pool = '0123456789abcdef';
             break;
         case 'numeric':
             $pool = '0123456789';
             break;
         case 'nozero':
             $pool = '123456789';
             break;
         case 'distinct':
             $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
             break;
         default:
             $pool = (string) $type;
             $utf8 = !utf8::is_ascii($pool);
             break;
     }
     // Split the pool into an array of characters
     $pool = $utf8 === TRUE ? utf8::str_split($pool, 1) : str_split($pool, 1);
     // Largest pool key
     $max = count($pool) - 1;
     $str = '';
     for ($i = 0; $i < $length; $i++) {
         // Select a random character from the pool and add it to the string
         $str .= $pool[mt_rand(0, $max)];
     }
     // Make sure alnum strings contain at least one letter and one digit
     if ($type === 'alnum' and $length > 1) {
         if (ctype_alpha($str)) {
             // Add a random digit
             $str[mt_rand(0, $length - 1)] = chr(mt_rand(48, 57));
         } elseif (ctype_digit($str)) {
             // Add a random letter
             $str[mt_rand(0, $length - 1)] = chr(mt_rand(65, 90));
         }
     }
     return $str;
 }