Selaa lähdekoodia

[Locale] refactor IntlDateFormatter::format to build regExp dynamically

Igor Wiedler 14 vuotta sitten
vanhempi
commit
42a652ce3d
1 muutettua tiedostoa jossa 6 lisäystä ja 1 poistoa
  1. 6 1
      src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

+ 6 - 1
src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

@@ -40,7 +40,12 @@ class StubIntlDateFormatter
 
     public function format($timestamp)
     {
-        $regExp = "/('(M+|L+|y+|d+|G+|Q+|q+|h+|D+|E+|a+|H+|[^MLydGQqhDEaH])|M+|L+|y+|d+|G+|Q+|q+|h+|D+|E+|a+|H+)/";
+        $specialChars = 'MLydGQqhDEaH';
+        $specialCharsArray = str_split($specialChars);
+        $specialCharsMatch = implode('|', array_map(function($char) {
+            return $char . '+';
+        }, $specialCharsArray));
+        $regExp = "/('($specialCharsMatch|[^$specialChars])|$specialCharsMatch)/";
 
         $callback = function($matches) use ($timestamp) {
             $pattern = $matches[0];