Inline private 'is quoting required' methods in Escaper
This commit is contained in:
parent
afe827ae9c
commit
8fa056bc95
|
@ -72,7 +72,15 @@ class Escaper
|
|||
*/
|
||||
public static function requiresSingleQuoting($value)
|
||||
{
|
||||
return self::containsCharRequiresSingleQuoting($value) || self::isValueRequiresSingleQuoting($value);
|
||||
// Determines if the PHP value contains any single characters that would
|
||||
// cause it to require single quoting in YAML.
|
||||
if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Determines if a PHP value is entirely composed of a value that would
|
||||
// require single quoting in YAML.
|
||||
return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,30 +94,4 @@ class Escaper
|
|||
{
|
||||
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a PHP value contains any single characters that would cause
|
||||
* the value to require single quoting in YAML.
|
||||
*
|
||||
* @param string $value A PHP value
|
||||
* @return bool True if the value would require single quotes.
|
||||
*/
|
||||
private static function containsCharRequiresSingleQuoting($value)
|
||||
{
|
||||
return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a PHP value is entirely composed of a value that would
|
||||
* require single quoting in YAML.
|
||||
*
|
||||
* @param string $value A PHP value
|
||||
* @return bool True if the value would require single quotes.
|
||||
*/
|
||||
private static function isValueRequiresSingleQuoting($value)
|
||||
{
|
||||
// Note that whilst 'y' and 'n' are not supported as valid Booleans,
|
||||
// they are escaped here for interoperability.
|
||||
return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'));
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue