Exemple #1
0
<?php

mb_regex_set_options('');
$encs = array('EUC-JP', 'Shift_JIS', 'SJIS', 'UTF-8');
function test_search($test_enc, $str, $look_for, $opt, $in_enc = 'EUC-JP')
{
    mb_regex_encoding($test_enc);
    $str = mb_convert_encoding($str, $test_enc, $in_enc);
    $look_for = mb_convert_encoding($look_for, $test_enc, $in_enc);
    mb_ereg_search_init($str, $look_for, $opt);
    while (mb_ereg_search_pos()) {
        $regs = mb_ereg_search_getregs();
        array_shift($regs);
        printf("(%s) (%d) %s\n", $test_enc, mb_ereg_search_getpos(), mb_convert_encoding(is_array($regs) ? implode('-', $regs) : '', $in_enc, $test_enc));
    }
}
function do_tests($enc, $opt)
{
    test_search($enc, "�ϡ� ����\n", ' (��?�ϡ�?)[[:space:]]', $opt);
    test_search($enc, 'abcde abdeabcf anvfabc odu abcd ', '(ab[a-z]+)', $opt);
}
foreach ($encs as $enc) {
    do_tests($enc, '');
    do_tests($enc, 'x');
}
?>

Exemple #2
0
<?php

mb_regex_set_options('');
$encs = array('EUC-JP', 'Shift_JIS', 'SJIS', 'UTF-8');
function test_ereg($test_enc, $pat, $str, $in_enc = 'EUC-JP')
{
    mb_regex_encoding($test_enc);
    $pat = mb_convert_encoding($pat, $test_enc, $in_enc);
    $str = mb_convert_encoding($str, $test_enc, $in_enc);
    printf("(%d)%s\n", mb_ereg($pat, $str, $reg), is_array($reg) ? bin2hex(mb_convert_encoding(implode(' ', $reg), $in_enc, $test_enc)) : '');
}
function do_tests($enc)
{
    test_ereg($enc, 'abc ([a-z]+) ([a-z]+) ([a-z]+)$', "abc def ghi jkl");
    $pat = '([a-z]+) ([ あ-か]+)([か-な]+) ([わ-ん]+)$';
    test_ereg($enc, $pat, 'abc あおい かこな わゑん');
    test_ereg($enc, $pat, 'mzxfp うおか きか をゐ');
}
foreach ($encs as $enc) {
    do_tests($enc);
}
?>

Exemple #3
0
$options = getopt('f:hi:');
if (isset($options['h'])) {
    help();
    exit;
}
if (!empty($options['f'])) {
    $csv_file = $options['f'];
    if (preg_match('/[.]csv$/i', $csv_file) <= 0) {
        $csv_file .= '.csv';
    }
}
if (!empty($options['i']) && is_numeric($options['i'])) {
    $base = $options['i'];
}
if ($base < MIN_BASE) {
    die('Min iterations = ' . MIN_BASE . "\n");
}
if (empty($options)) {
    help();
}
echo 'Starting the benchmark with ' . $base . ' iterations.' . "\n\n";
$tests_list = array();
$results = array();
if (load_tests($TESTS_DIRS, $tests_list) === FALSE) {
    die('Unable to load tests');
}
echo "\n";
do_tests($base, $tests_list, $results);
echo "\n";
show_summary($base, $results, $csv_file);
echo "\n";