(add|remove)(Leading|Trailing)Slash rewritten
authorTim Düsterhus <timwolla@arcor.de>
Wed, 14 Dec 2011 18:49:01 +0000 (19:49 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Wed, 14 Dec 2011 18:49:01 +0000 (19:49 +0100)
wcfsetup/install/files/lib/util/FileUtil.class.php

index 8139aa3c285089ab715466c4cebd524fee9dff13..037f2448e819cc6d8eee10798eb5f7f61d718bc0 100644 (file)
@@ -41,12 +41,7 @@ class FileUtil {
         * @return      string          $path
         */
        public static function removeLeadingSlash($path) {
-               if (substr($path, 0, 1) == '/') {
-                       return substr($path, 1);
-               }
-               else {
-                       return $path;   
-               }       
+               return ltrim($path, '/');
        }
 
        /**
@@ -56,12 +51,7 @@ class FileUtil {
         * @return      string          $path
         */
        public static function removeTrailingSlash($path) {
-               if (substr($path, -1) == '/') {
-                       return substr($path, 0, -1);
-               }
-               else {
-                       return $path;
-               }       
+               return rtrim($path, '/');
        }
        
        /**
@@ -71,11 +61,7 @@ class FileUtil {
         * @return      string          $path
         */
        public static function addTrailingSlash($path) {
-               if (substr($path, -1) != '/') {
-                       return $path.'/';
-               }
-               
-               return $path;
+               return rtrim($path, '/').'/';
        }
        
        /**
@@ -85,11 +71,7 @@ class FileUtil {
         * @return      string          $path
         */
        public static function addLeadingSlash($path) {
-               if (substr($path, 0, 1) != '/') {
-                       return '/'.$path;
-               }
-               
-               return $path;
+               return '/'.ltrim($path, '/');
        }
 
        /**