Revert "[TASK] Improve performance of trimExplode" 23/38523/2
authorNicole Cordes <typo3@cordes.co>
Wed, 8 Apr 2015 07:45:26 +0000 (09:45 +0200)
committerNicole Cordes <typo3@cordes.co>
Wed, 8 Apr 2015 07:45:33 +0000 (09:45 +0200)
This reverts commit 27723ecb9770b41a898c2bebacded99ec58a9a50. This needs to be done as the current solution for GeneralUtility::trimExplode can't handly whitespaces as delim parameter

Change-Id: I4ccc12e01b949c18f61ad4930e3c57893a9a1cf5
Reviewed-on: http://review.typo3.org/38523
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 75cd4a7..24e60b0 100755 (executable)
@@ -1471,9 +1471,19 @@ class GeneralUtility {
         * @return array Exploded values
         */
        static public function trimExplode($delim, $string, $removeEmptyValues = FALSE, $limit = 0) {
-               $result = preg_split('/\s*+' . preg_quote($delim, '/') . '\s*+/', trim($string), NULL, $removeEmptyValues ? PREG_SPLIT_NO_EMPTY : NULL);
+               $result = array_map('trim', explode($delim, $string));
+               if ($removeEmptyValues) {
+                       $temp = array();
+                       foreach ($result as $value) {
+                               if ($value !== '') {
+                                       $temp[] = $value;
+                               }
+                       }
+                       $result = $temp;
+               }
                if ($limit > 0 && count($result) > $limit) {
-                       $result = explode($delim, implode($delim, $result), $limit);
+                       $lastElements = array_splice($result, $limit - 1);
+                       $result[] = implode($delim, $lastElements);
                } elseif ($limit < 0) {
                        $result = array_slice($result, 0, $limit);
                }
index 46f70d4..7a010f1 100644 (file)
@@ -1305,26 +1305,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertEquals($expectedArray, $actualArray);
        }
 
-       /**
-        * @test
-        */
-       public function checkTrimExplodeKeepsWhitespaceInsideElements() {
-               $testString = 'a , b , c , ,d ,, ,e,f, g h ,';
-               $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', 'g h');
-               $actualArray = Utility\GeneralUtility::trimExplode(',', $testString, TRUE);
-               $this->assertEquals($expectedArray, $actualArray);
-       }
-
-       /**
-        * @test
-        */
-       public function checkTrimExplodeCanUseInternalRegexDelimiterAsExplodeDelimiter() {
-               $testString = 'a / b / c / /d // /e/f/ g h /';
-               $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', 'g h');
-               $actualArray = Utility\GeneralUtility::trimExplode('/', $testString, TRUE);
-               $this->assertEquals($expectedArray, $actualArray);
-       }
-
        //////////////////////////////////
        // Tests concerning getBytesFromSizeMeasurement
        //////////////////////////////////