<?php
namespace Symfony\Component\Yaml;
class Escaper {
const REGEX_CHARACTER_TO_ESCAPE = "[\\x00-\\x1f]|
| |
|
";
private static $escapees = array(
'\\\\',
'\\"',
'"',
"\0",
"\1",
"\2",
"\3",
"\4",
"\5",
"\6",
"\7",
"\10",
"\t",
"\n",
"\v",
"\f",
"\r",
"\16",
"\17",
"\20",
"\21",
"\22",
"\23",
"\24",
"\25",
"\26",
"\27",
"\30",
"\31",
"\32",
"\33",
"\34",
"\35",
"\36",
"\37",
"
",
" ",
"
",
"
",
);
private static $escaped = array(
'\\"',
'\\\\',
'\\"',
"\\0",
"\\x01",
"\\x02",
"\\x03",
"\\x04",
"\\x05",
"\\x06",
"\\a",
"\\b",
"\\t",
"\\n",
"\\v",
"\\f",
"\\r",
"\\x0e",
"\\x0f",
"\\x10",
"\\x11",
"\\x12",
"\\x13",
"\\x14",
"\\x15",
"\\x16",
"\\x17",
"\\x18",
"\\x19",
"\\x1a",
"\\e",
"\\x1c",
"\\x1d",
"\\x1e",
"\\x1f",
"\\N",
"\\_",
"\\L",
"\\P",
);
public static function requiresDoubleQuoting($value) {
return preg_match('/' . self::REGEX_CHARACTER_TO_ESCAPE . '/u', $value);
}
public static function escapeWithDoubleQuotes($value) {
return sprintf('"%s"', str_replace(self::$escapees, self::$escaped, $value));
}
public static function requiresSingleQuoting($value) {
return preg_match('/[ \\s \' " \\: \\{ \\} \\[ \\] , & \\* \\# \\?] | \\A[ - ? | < > = ! % @ ` ]/x', $value);
}
public static function escapeWithSingleQuotes($value) {
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
}
}