Changeset View
Changeset View
Standalone View
Standalone View
src/utils/utils.php
Context not available. | |||||
* @phutil-external-symbol function phutil_safe_html | * @phutil-external-symbol function phutil_safe_html | ||||
*/ | */ | ||||
function phutil_split_lines($corpus, $retain_endings = true) { | function phutil_split_lines($corpus, $retain_endings = true) { | ||||
if (!strlen($corpus)) { | if (!@strlen($corpus)) { | ||||
return array(''); | return array(''); | ||||
} | } | ||||
Context not available. | |||||
* for printing on a single log line. | * for printing on a single log line. | ||||
*/ | */ | ||||
function phutil_loggable_string($string) { | function phutil_loggable_string($string) { | ||||
if (preg_match('/^[\x20-\x7E]+$/', $string)) { | if (@preg_match('/^[\x20-\x7E]+$/', $string)) { | ||||
return $string; | return $string; | ||||
} | } | ||||
Context not available. | |||||
"\t" => '\\t', | "\t" => '\\t', | ||||
); | ); | ||||
$len = strlen($string); | $len = @strlen($string); | ||||
for ($ii = 0; $ii < $len; $ii++) { | for ($ii = 0; $ii < $len; $ii++) { | ||||
$c = $string[$ii]; | $c = $string[$ii]; | ||||
if (isset($c_map[$c])) { | if (isset($c_map[$c])) { | ||||
Context not available. | |||||
* errors which `fwrite()` can not detect, like a broken pipe). | * errors which `fwrite()` can not detect, like a broken pipe). | ||||
*/ | */ | ||||
function phutil_fwrite_nonblocking_stream($stream, $bytes) { | function phutil_fwrite_nonblocking_stream($stream, $bytes) { | ||||
if (!strlen($bytes)) { | if (!@strlen($bytes)) { | ||||
return 0; | return 0; | ||||
} | } | ||||
Context not available. | |||||
*/ | */ | ||||
function phutil_units($description) { | function phutil_units($description) { | ||||
$matches = null; | $matches = null; | ||||
if (!preg_match('/^(\d+) (\w+) in (\w+)$/', $description, $matches)) { | if (!@preg_match('/^(\d+) (\w+) in (\w+)$/', $description, $matches)) { | ||||
throw new InvalidArgumentException( | throw new InvalidArgumentException( | ||||
pht( | pht( | ||||
'Unable to parse unit specification (expected a specification in the '. | 'Unable to parse unit specification (expected a specification in the '. | ||||
Context not available. | |||||
if (is_array($value)) { | if (is_array($value)) { | ||||
foreach ($value as $key => $subvalue) { | foreach ($value as $key => $subvalue) { | ||||
if (strlen($path)) { | if (@strlen($path)) { | ||||
$full_key = $path.' > '; | $full_key = $path.' > '; | ||||
} else { | } else { | ||||
$full_key = ''; | $full_key = ''; | ||||
Context not available. | |||||
if (is_string($value)) { | if (is_string($value)) { | ||||
if (!phutil_is_utf8($value)) { | if (!phutil_is_utf8($value)) { | ||||
$display = substr($value, 0, 256); | $display = @substr($value, 0, 256); | ||||
$display = phutil_utf8ize($display); | $display = phutil_utf8ize($display); | ||||
if (!strlen($path)) { | if (!@strlen($path)) { | ||||
return pht( | return pht( | ||||
'String value is not valid UTF8, and can not be JSON encoded: %s', | 'String value is not valid UTF8, and can not be JSON encoded: %s', | ||||
$display); | $display); | ||||
Context not available. | |||||
$in_curlies = 0; | $in_curlies = 0; | ||||
$regex = ''; | $regex = ''; | ||||
for ($i = 0; $i < strlen($glob); $i++) { | for ($i = 0; $i < @strlen($glob); $i++) { | ||||
$char = $glob[$i]; | $char = $glob[$i]; | ||||
$next_char = ($i < strlen($glob) - 1) ? $glob[$i + 1] : null; | $next_char = ($i < @strlen($glob) - 1) ? $glob[$i + 1] : null; | ||||
$escape = array('$', '(', ')', '+', '.', '^', '|'); | $escape = array('$', '(', ')', '+', '.', '^', '|'); | ||||
$mapping = array(); | $mapping = array(); | ||||
Context not available. | |||||
} | } | ||||
$regex = '(\A'.$regex.'\z)'; | $regex = '(\A'.$regex.'\z)'; | ||||
return (bool)preg_match($regex, $path); | return (bool)@preg_match($regex, $path); | ||||
} | } | ||||
Context not available. | |||||
throw new Exception(pht('Second hash argument must be a string.')); | throw new Exception(pht('Second hash argument must be a string.')); | ||||
} | } | ||||
if (strlen($u) !== strlen($v)) { | if (@strlen($u) !== @strlen($v)) { | ||||
return false; | return false; | ||||
} | } | ||||
$len = strlen($v); | $len = @strlen($v); | ||||
$bits = 0; | $bits = 0; | ||||
for ($ii = 0; $ii < $len; $ii++) { | for ($ii = 0; $ii < $len; $ii++) { | ||||
Context not available. | |||||
return $partitions; | return $partitions; | ||||
} | } | ||||
function phutil_preg_match( | function phutilpreg_match( | ||||
$pattern, | $pattern, | ||||
$subject, | $subject, | ||||
$flags = 0, | $flags = 0, | ||||
$offset = 0) { | $offset = 0) { | ||||
$matches = null; | $matches = null; | ||||
$result = @preg_match($pattern, $subject, $matches, $flags, $offset); | $result = @@preg_match($pattern, $subject, $matches, $flags, $offset); | ||||
if ($result === false || $result === null) { | if ($result === false || $result === null) { | ||||
phutil_raise_preg_exception( | phutil_raise_preg_exception( | ||||
'preg_match', | 'preg_match', | ||||
Context not available. | |||||
switch ($function) { | switch ($function) { | ||||
case 'preg_match': | case 'preg_match': | ||||
@preg_match($argv[0], $argv[1], $argv[2], $argv[3], $argv[4]); | @@preg_match($argv[0], $argv[1], $argv[2], $argv[3], $argv[4]); | ||||
break; | break; | ||||
case 'preg_match_all': | case 'preg_match_all': | ||||
@preg_match_all($argv[0], $argv[1], $argv[2], $argv[3], $argv[4]); | @preg_match_all($argv[0], $argv[1], $argv[2], $argv[3], $argv[4]); | ||||
Context not available. | |||||
$function, | $function, | ||||
$pattern_display); | $pattern_display); | ||||
if (strlen($error_message)) { | if (@strlen($error_message)) { | ||||
$message[] = pht( | $message[] = pht( | ||||
'Regular expression engine emitted message: %s', | 'Regular expression engine emitted message: %s', | ||||
$error_message); | $error_message); | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0