Issue #306 - Testing the multibyte string library, corrections about the functions api_ucwords() and api_substr_replace(). Now the stanalone test makes successfully all passes (135) on Windows and Linux machines.

skala
Ivan Tcholakov 17 years ago
parent c42ebb542d
commit c5a9ffb9bb
  1. 16
      main/inc/lib/multibyte_string_functions.lib.php
  2. 8
      tests/main/inc/lib/multibyte_string_functions.lib.test.php

@ -1399,16 +1399,26 @@ function api_substr_replace($string, $replacement, $start, $length = null, $enco
$encoding = _api_mb_internal_encoding();
}
if (_api_is_single_byte_encoding($encoding)) {
if (is_null($length)) {
return substr_replace($string, $replacement, $start);
}
return substr_replace($string, $replacement, $start, $length);
}
if (api_is_encoding_supported($encoding)) {
if (is_null($length)) {
$length = api_strlen($string);
}
if ($start > 0) {
return api_substr($string, 0, $start) . $replacement . api_substr($string, $start + $length);
if (!api_is_utf8($encoding)) {
$string = api_utf8_encode($string, $encoding);
$replacement = api_utf8_encode($replacement, $encoding);
}
$string = _api_utf8_to_unicode($string);
array_splice($string, $start, $length, _api_utf8_to_unicode($replacement));
$string = _api_utf8_from_unicode($string);
if (!api_is_utf8($encoding)) {
$string = api_utf8_decode($string, $encoding);
}
return $replacement . api_substr($string, $start + $length);
return $string;
}
if (is_null($length)) {
return substr_replace($string, $replacement, $start);

@ -306,22 +306,22 @@ class TestMultibyte_String_Functions extends UnitTestCase {
}
public function test_api_ucfirst() {
$string = 'áéíóúº|\/?Ç][ç]'; // UTF-8
$string = 'áéíóúº|\/? xx ][ xx ]'; // UTF-8
$encoding = 'UTF-8';
$res = api_ucfirst($string, $encoding);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
$this->assertTrue($res == 'Áéíóúº|\/?Ç][ç]');
$this->assertTrue($res == 'Áéíóúº|\/? xx ][ xx ]');
//var_dump($res);
}
public function test_api_ucwords() {
$string = 'áéí óúº|\/?Ç][ ç]'; // UTF-8
$string = 'áéíóúº|\/? xx ][ xx ]'; // UTF-8
$encoding = 'UTF-8';
$res = api_ucwords($string, $encoding);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
$this->assertTrue($res == 'Áéí Óúº|\/?Ç][ Ç]');
$this->assertTrue($res == 'Áéíóúº|\/? Xx ][ Xx ]');
//var_dump($res);
}

Loading…
Cancel
Save