Skip to content
Permalink
Browse files

Reduce amount of trimming on strings

  • Loading branch information
flodolo committed Nov 7, 2016
1 parent e53e117 commit 6b715e2c8e736ecb89282ed9dc4041a7d2c50fed
@@ -132,7 +132,7 @@ public function __construct()
*/
public function setSearchTerms($string)
{
$this->search_terms = trim($string);
$this->search_terms = $string;
$this->regex_search_terms = $this->search_terms;
$this->updateRegex();

@@ -173,7 +173,7 @@ public static function getRepositorySearchResults($entities, $array_strings)
$output = [];

$clean_string = function ($string) {
return trim(htmlspecialchars_decode($string, ENT_QUOTES));
return htmlspecialchars_decode($string, ENT_QUOTES);
};

foreach ($search_results as $entity => $set) {
@@ -289,8 +289,8 @@ public static function resultsTable($search_object, $search_results, $page)

$component = explode('/', $key)[0];
$fileAndRawString = explode(':', $key);
$source_string = trim($strings[0]);
$target_string = trim($strings[1]);
$source_string = $strings[0];
$target_string = $strings[1];

$entity_link = "?sourcelocale={$locale1}"
. "&locale={$locale2}"
@@ -303,7 +303,7 @@ public static function resultsTable($search_object, $search_results, $page)
)];

if ($extra_locale) {
$target_string2 = trim($strings[2]);
$target_string2 = $strings[2];
$entity_link = "?sourcelocale={$locale1}"
. "&locale={$search_object->getLocale('extra')}"
. "&repo={$current_repo}"
@@ -11,18 +11,16 @@
class Strings
{
/**
* Replace contiguous spaces in a string by a single space
* Replace contiguous spaces in a string by a single space.
* Leading and trailing spaces are preserved but collapsed
* to a single space.
*
* @param string $string The string to analyze
* @return string Cleaned up string with extra spaces merged
*/
public static function mtrim($string)
{
$string = explode(' ', $string);
$string = array_filter($string);
$string = implode(' ', $string);

return $string;
return preg_replace('/\s+/', ' ', $string);
}

/**
@@ -233,9 +233,6 @@ public static function cleanString($string)
return '';
}

// Filter out double spaces
$string = Strings::mtrim($string);

return $string;
}

@@ -12,9 +12,9 @@
$strings = Utils::getRepoStrings($locale_code, $repo);

if (isset($strings[$entity])) {
$strings[$entity] = trim($strings[$entity]);
$strings[$entity] = $strings[$entity];
if (Strings::endsWith(strtolower($strings[$entity]), '{ok}')) {
$strings[$entity] = trim(substr($strings[$entity], 0, -4));
$strings[$entity] = substr($strings[$entity], 0, -4);
}
$translations[$locale_code] = $strings[$entity];
}
@@ -60,10 +60,10 @@ public function testSetSearchTerms()
$obj->setSearchTerms(' foobar ');
$this
->string($obj->getSearchTerms())
->isEqualTo('foobar');
->isEqualTo(' foobar ');
$this
->string($obj->getRegexSearchTerms())
->isEqualTo('foobar');
->isEqualTo(' foobar ');
}

public function testSetRegexSearchTerms()
@@ -10,18 +10,23 @@ class Strings extends atoum\test
{
public function mtrimDP()
{
return ['Le cheval blanc '];
return [
['Le cheval blanc ', 'Le cheval blanc '],
[' Le cheval blanc', ' Le cheval blanc'],
[' Le cheval blanc ', ' Le cheval blanc '],
['Le cheval blanc', 'Le cheval blanc'],
];
}

/**
* @dataProvider mtrimDP
*/
public function testMtrim($a)
public function testMtrim($a, $b)
{
$obj = new _Strings();
$this
->string($obj->mtrim($a))
->isEqualTo('Le cheval blanc');
->isEqualTo($b);
}

public function startsWithDP()
@@ -178,12 +178,8 @@ public function cleanStringDP()
{
return [
[
'pages web fréquemment visitées (en cliquant sur « Recharger »,',
'pages web fréquemment visitées (en cliquant sur « Recharger »,',
],
[
'toto ',
'toto',
[],
'',
],
[
"don\u0027t strip unicode escaped chars",
@@ -512,6 +512,7 @@ table tr td.no_highligth {
color: #000;
background-color: rgba(255, 165, 0, 0.77);
border-radius: 3px;
white-space: pre-wrap;
}

.superset {

0 comments on commit 6b715e2

Please sign in to comment.
You can’t perform that action at this time.