[TASK] Replace simple preg_replace calls with trim 63/31763/6
authorBenjamin Mack <benni@b13.de>
Thu, 24 Jul 2014 14:06:52 +0000 (16:06 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Sun, 4 Jan 2015 21:25:47 +0000 (22:25 +0100)
There are a few occurrences where simple preg_replace calls are used
even though this can be accomplished with rtrim() or ltrim().
This improves readability and (maybe ;)) speed.

Resolves: #60534
Releases: master
Change-Id: Id834ce49df0f60a75f855c403ec15a79381d928d
Reviewed-on: http://review.typo3.org/31763
Reviewed-by: Stefan Froemken <froemken@gmail.com>
Tested-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/backend/Classes/Controller/ContentElement/NewContentElementController.php
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Utility/File/BasicFileUtility.php

index eedb2c5..2c8fde6 100644 (file)
@@ -337,7 +337,7 @@ class NewContentElementController {
                $wizardItems = array();
                if (is_array($wizards)) {
                        foreach ($wizards as $groupKey => $wizardGroup) {
-                               $groupKey = preg_replace('/\\.$/', '', $groupKey);
+                               $groupKey = rtrim($groupKey, '.');
                                $showItems = GeneralUtility::trimExplode(',', $wizardGroup['show'], TRUE);
                                $showAll = $wizardGroup['show'] === '*';
                                $groupItems = array();
@@ -348,7 +348,7 @@ class NewContentElementController {
                                }
                                if (is_array($wizardElements)) {
                                        foreach ($wizardElements as $itemKey => $itemConf) {
-                                               $itemKey = preg_replace('/\\.$/', '', $itemKey);
+                                               $itemKey = rtrim($itemKey, '.');
                                                if ($showAll || in_array($itemKey, $showItems)) {
                                                        $tmpItem = $this->wizard_getItem($groupKey, $itemKey, $itemConf);
                                                        if ($tmpItem) {
index 5748824..9062a36 100644 (file)
@@ -1341,11 +1341,10 @@ function jumpToUrl(URL) {
                        // <script wrapped in nl?
                        $cr = $linebreak ? LF : '';
                        // Remove nl from the beginning
-                       $string = preg_replace('/^\\n+/', '', $string);
+                       $string = ltrim($string, LF);
                        // Re-ident to one tab using the first line as reference
-                       $match = array();
-                       if (preg_match('/^(\\t+)/', $string, $match)) {
-                               $string = str_replace($match[1], TAB, $string);
+                       if ($string[0] === TAB) {
+                               $string = TAB . ltrim($string, TAB);
                        }
                        $string = $cr . '<script type="text/javascript">
 /*<![CDATA[*/
index db6589b..961f61c 100644 (file)
@@ -318,7 +318,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
                        $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . '\\xC0-\\xFF]/', '_', trim($fileName));
                }
                // Strip trailing dots and return
-               $cleanFileName = preg_replace('/\\.*$/', '', $cleanFileName);
+               $cleanFileName = rtrim($cleanFileName, '.');
                if (!$cleanFileName) {
                        throw new Exception\InvalidFileNameException(
                                'File name ' . $cleanFileName . ' is invalid.',
index edf99e3..83ebdce 100644 (file)
@@ -420,7 +420,7 @@ class BasicFileUtility {
                        $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . '\\xC0-\\xFF]/', '_', trim($fileName));
                }
                // Strip trailing dots and return
-               return preg_replace('/\\.*$/', '', $cleanFileName);
+               return rtrim($cleanFileName, '.');
        }
 
 }