@@ -72,7 +72,15 @@ public static function escapeWithDoubleQuotes($value)
72
72
*/
73
73
public static function requiresSingleQuoting ($ value )
74
74
{
75
- return self ::containsCharRequiresSingleQuoting ($ value ) || self ::isValueRequiresSingleQuoting ($ value );
75
+ // Determines if the PHP value contains any single characters that would
76
+ // cause it to require single quoting in YAML.
77
+ if (preg_match ('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x ' , $ value )) {
78
+ return true ;
79
+ }
80
+
81
+ // Determines if a PHP value is entirely composed of a value that would
82
+ // require single quoting in YAML.
83
+ return in_array (strtolower ($ value ), array ('null ' , '~ ' , 'true ' , 'false ' , 'y ' , 'n ' , 'yes ' , 'no ' , 'on ' , 'off ' ));
76
84
}
77
85
78
86
/**
@@ -86,30 +94,4 @@ public static function escapeWithSingleQuotes($value)
86
94
{
87
95
return sprintf ("'%s' " , str_replace ('\'' , '\'\'' , $ value ));
88
96
}
89
-
90
- /**
91
- * Determines if a PHP value contains any single characters that would cause
92
- * the value to require single quoting in YAML.
93
- *
94
- * @param string $value A PHP value
95
- * @return bool True if the value would require single quotes.
96
- */
97
- private static function containsCharRequiresSingleQuoting ($ value )
98
- {
99
- return preg_match ('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x ' , $ value );
100
- }
101
-
102
- /**
103
- * Determines if a PHP value is entirely composed of a value that would
104
- * require single quoting in YAML.
105
- *
106
- * @param string $value A PHP value
107
- * @return bool True if the value would require single quotes.
108
- */
109
- private static function isValueRequiresSingleQuoting ($ value )
110
- {
111
- // Note that whilst 'y' and 'n' are not supported as valid Booleans,
112
- // they are escaped here for interoperability.
113
- return in_array (strtolower ($ value ), array ('null ' , '~ ' , 'true ' , 'false ' , 'y ' , 'n ' , 'yes ' , 'no ' , 'on ' , 'off ' ));
114
- }
115
97
}
0 commit comments