comparison vendor/symfony/translation/Extractor/PhpStringTokenParser.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 */ 48 */
49 49
50 class PhpStringTokenParser 50 class PhpStringTokenParser
51 { 51 {
52 protected static $replacements = array( 52 protected static $replacements = [
53 '\\' => '\\', 53 '\\' => '\\',
54 '$' => '$', 54 '$' => '$',
55 'n' => "\n", 55 'n' => "\n",
56 'r' => "\r", 56 'r' => "\r",
57 't' => "\t", 57 't' => "\t",
58 'f' => "\f", 58 'f' => "\f",
59 'v' => "\v", 59 'v' => "\v",
60 'e' => "\x1B", 60 'e' => "\x1B",
61 ); 61 ];
62 62
63 /** 63 /**
64 * Parses a string token. 64 * Parses a string token.
65 * 65 *
66 * @param string $str String token content 66 * @param string $str String token content
74 $bLength = 1; 74 $bLength = 1;
75 } 75 }
76 76
77 if ('\'' === $str[$bLength]) { 77 if ('\'' === $str[$bLength]) {
78 return str_replace( 78 return str_replace(
79 array('\\\\', '\\\''), 79 ['\\\\', '\\\''],
80 array('\\', '\''), 80 ['\\', '\''],
81 substr($str, $bLength + 1, -1) 81 substr($str, $bLength + 1, -1)
82 ); 82 );
83 } else { 83 } else {
84 return self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"'); 84 return self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"');
85 } 85 }
87 87
88 /** 88 /**
89 * Parses escape sequences in strings (all string types apart from single quoted). 89 * Parses escape sequences in strings (all string types apart from single quoted).
90 * 90 *
91 * @param string $str String without quotes 91 * @param string $str String without quotes
92 * @param null|string $quote Quote type 92 * @param string|null $quote Quote type
93 * 93 *
94 * @return string String with escape sequences parsed 94 * @return string String with escape sequences parsed
95 */ 95 */
96 public static function parseEscapeSequences($str, $quote) 96 public static function parseEscapeSequences($str, $quote)
97 { 97 {
99 $str = str_replace('\\'.$quote, $quote, $str); 99 $str = str_replace('\\'.$quote, $quote, $str);
100 } 100 }
101 101
102 return preg_replace_callback( 102 return preg_replace_callback(
103 '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3})~', 103 '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3})~',
104 array(__CLASS__, 'parseCallback'), 104 [__CLASS__, 'parseCallback'],
105 $str 105 $str
106 ); 106 );
107 } 107 }
108 108
109 private static function parseCallback($matches) 109 private static function parseCallback($matches)
111 $str = $matches[1]; 111 $str = $matches[1];
112 112
113 if (isset(self::$replacements[$str])) { 113 if (isset(self::$replacements[$str])) {
114 return self::$replacements[$str]; 114 return self::$replacements[$str];
115 } elseif ('x' === $str[0] || 'X' === $str[0]) { 115 } elseif ('x' === $str[0] || 'X' === $str[0]) {
116 return chr(hexdec($str)); 116 return \chr(hexdec($str));
117 } else { 117 } else {
118 return chr(octdec($str)); 118 return \chr(octdec($str));
119 } 119 }
120 } 120 }
121 121
122 /** 122 /**
123 * Parses a constant doc string. 123 * Parses a constant doc string.