Skip to content
Snippets Groups Projects
Commit 0e70946d authored by chris's avatar chris
Browse files

add unittests for bug#891

darcs-hash:20060831092146-9b6ab-b00aa29c982ab18117f476b3d01d5111915c9d4b.gz
parent 9ee93076
No related branches found
No related tags found
No related merge requests found
......@@ -26,5 +26,18 @@ class utf8_substr_test extends UnitTestCase {
}
}
function test2_bug891() {
// we test multiple cases here - format: in, offset, length, out
$tests = array();
$str = str_pad('',strlen('в')*66000,'в').'@@';
$tests[] = array($str, 65600, 1, 'в');
$tests[] = array($str,0,66000,$str);
foreach($tests as $test){
$this->assertEqual(utf8_substr($test[0],$test[1],$test[2]),$test[3]);
}
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
......@@ -333,7 +333,6 @@ switch ($algorithm) {
// establish context, 100 bytes surrounding the match string
// first look to see if we can go 100 either side,
// then drop to 50 adding any excess if the other side can't go to 50,
// NOTE: these are byte adjustments and will have to be corrected for utf-8
$pre = min($utf8_idx-$utf8_offset,100);
$post = min($len-$utf8_idx-$utf8_len,100);
......@@ -371,9 +370,9 @@ switch ($algorithm) {
} else {
// code for strings too large for utf8_substr
// use a larger context number as its bytes not characters
$pre = 70;
// no need to check for short pre, $idx is nearly 64k
$post = min(strlen($text)-$idx-strlen($str), 70);
if ($post < 70) { $pre = 70 - $post; }
$pre = ($post < 70) ? 140 - $post : 70;
$start = utf8_correctIdx($text,$idx - $pre);
$end = utf8_correctIdx($text, $idx + strlen($str) + $post);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment