Selaa lähdekoodia

Improved FilePathSeparator class

- combined unix preprocessor directives
- improved naming of methods
Patrick 4 vuotta sitten
vanhempi
commit
c9d2d3ca35
3 muutettua tiedostoa jossa 12 lisäystä ja 15 poistoa
  1. 2 2
      source/io/File.cpp
  2. 8 11
      source/io/FilePathSeparator.hpp
  3. 2 2
      source/io/FilePathSeparatorMatch.hpp

+ 2 - 2
source/io/File.cpp

@@ -287,8 +287,8 @@ int ls_std::File::_mkdir(const std::string& _path) {
 
 std::string ls_std::File::_normalizePath(std::string _path)
 {
-  const char unixSeparator = ls_std::FilePathSeparator::getLinuxFilePathSeparator();
-  const char windowsSeparator = ls_std::FilePathSeparator::getUnixFilePathSeparator();
+  const char unixSeparator = ls_std::FilePathSeparator::getUnixFilePathSeparator();
+  const char windowsSeparator = ls_std::FilePathSeparator::getWindowsFilePathSeparator();
 
   #if defined(unix) || defined(__APPLE__)
     std::replace(_path.begin(), _path.end(), windowsSeparator, unixSeparator);

+ 8 - 11
source/io/FilePathSeparator.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-15
- * Changed:         2020-08-16
+ * Changed:         2020-08-17
  *
  * */
 
@@ -19,27 +19,24 @@ namespace ls_std {
       FilePathSeparator() = default;
       ~FilePathSeparator() = default;
 
-      static char getLinuxFilePathSeparator() {
-        return '/';
-      }
-
       static char getOperatingSystemSpecificSeparator() {
         char separator;
 
         #ifdef _WIN32
-          separator = ls_std::FilePathSeparator::getUnixFilePathSeparator();
-        #endif
-        #ifdef unix
-          separator = ls_std::FilePathSeparator::getLinuxFilePathSeparator();
+          separator = ls_std::FilePathSeparator::getWindowsFilePathSeparator();
         #endif
-        #ifdef __APPLE__
-          separator = ls_std::FilePathSeparator::getLinuxFilePathSeparator();
+        #if defined(unix) || defined(__APPLE__)
+          separator = ls_std::FilePathSeparator::getUnixFilePathSeparator();
         #endif
 
         return separator;
       }
 
       static char getUnixFilePathSeparator() {
+        return '/';
+      }
+
+      static char getWindowsFilePathSeparator() {
         return '\\';
       }
   };

+ 2 - 2
source/io/FilePathSeparatorMatch.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-15
- * Changed:         2020-08-15
+ * Changed:         2020-08-17
  *
  * */
 
@@ -15,7 +15,7 @@
 namespace ls_std {
   struct FilePathSeparatorMatch {
     bool operator()(char _char) const {
-      return _char == ls_std::FilePathSeparator::getUnixFilePathSeparator() || _char == ls_std::FilePathSeparator::getLinuxFilePathSeparator();
+      return _char == ls_std::FilePathSeparator::getWindowsFilePathSeparator() || _char == ls_std::FilePathSeparator::getUnixFilePathSeparator();
     }
   };
 }