Skip to content

Commit

Permalink
Inline private 'is quoting required' methods in Escaper
Browse files Browse the repository at this point in the history
  • Loading branch information
pthompson committed Jan 16, 2015
1 parent afe827a commit 8fa056b
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions src/Symfony/Component/Yaml/Escaper.php
Expand Up @@ -72,7 +72,15 @@ public static function escapeWithDoubleQuotes($value)
*/
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'));
}

/**
Expand All @@ -86,30 +94,4 @@ public static function escapeWithSingleQuotes($value)
{
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'));
}
}

0 comments on commit 8fa056b

Please sign in to comment.