2
0
forked from Wavyzz/dolibarr

Debug v18

This commit is contained in:
Laurent Destailleur
2023-05-25 15:11:16 +02:00
parent 5a6346f11b
commit 0c38eefd96
3 changed files with 52 additions and 11 deletions

View File

@@ -2909,3 +2909,42 @@ function acceptLocalLinktoMedia()
//return 1;
return $acceptlocallinktomedia;
}
/**
* Remove first and last parenthesis but only if first is the opening and last the closing of the same group
*
* @param string $string String to sanitize
* @return string String without global parenthesis
*/
function removeGlobalParenthesis($string)
{
$string = trim($string);
// If string does not start and end with parenthesis, we return $string as is.
if (! preg_match('/^\(.*\)$/', $string)) {
return $string;
}
$nbofchars = dol_strlen($string);
$i = 0; $g = 0;
$countparenthesis = 0;
while ($i < $nbofchars) {
$char = dol_substr($string, $i, 1);
if ($char == '(') {
$countparenthesis++;
} elseif ($char == ')') {
$countparenthesis--;
if ($countparenthesis <= 0) { // We reach the end of an independent group of parenthesis
$g++;
}
}
$i++;
}
if ($g <= 1) {
return preg_replace('/^\(/', '', preg_replace('/\)$/', '', $string));
}
return $string;
}