Daniele Bartolini 11 лет назад
Родитель
Сommit
b3f258b40a

+ 2 - 1
engine/core/filesystem/disk_filesystem.cpp

@@ -8,6 +8,7 @@
 #include "temp_allocator.h"
 #include "disk_file.h"
 #include "vector.h"
+#include "path.h"
 
 namespace crown
 {
@@ -132,7 +133,7 @@ void DiskFilesystem::list_files(const char* path, Vector<DynamicString>& files)
 
 void DiskFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
 {
-	if (os::is_absolute_path(path))
+	if (path::is_absolute_path(path))
 	{
 		os_path = path;
 		return;

+ 0 - 20
engine/core/os.h

@@ -59,26 +59,6 @@ namespace os
 #endif
 	}
 
-	inline bool is_root_path(const char* path)
-	{
-#if CROWN_PLATFORM_POSIX
-		return (path != NULL && strlen(path) == 1 && path[0] == PATH_SEPARATOR);
-#elif CROWN_PLATFORM_WINDOWS
-		return (path != NULL && strlen(path) == 3 && isalpha(path[0]) &&
-			path[1] == ':' && path[2] == PATH_SEPARATOR);
-#endif
-	}
-
-	inline bool is_absolute_path(const char* path)
-	{
-#if CROWN_PLATFORM_POSIX
-		return (path != NULL && strlen(path) >= 1 && path[0] == PATH_SEPARATOR);
-#elif CROWN_PLATFORM_WINDOWS
-		return (path != NULL && strlen(path) >= 3 && isalpha(path[0]) &&
-			path[1] == ':' && path[2] == PATH_SEPARATOR);
-#endif
-	}
-
 	inline bool exists(const char* path)
 	{
 #if CROWN_PLATFORM_POSIX

+ 21 - 0
engine/core/strings/path.cpp

@@ -4,6 +4,7 @@
  */
 
 #include "path.h"
+#include <ctype.h> // isalpha
 
 namespace crown
 {
@@ -91,6 +92,26 @@ namespace path
 		return true;
 	}
 
+	bool is_absolute_path(const char* path)
+	{
+		CE_ASSERT(path != NULL, "Path must be != NULL");
+#if CROWN_PLATFORM_POSIX
+		return strlen(path) > 0 && path[0] == '/';
+#elif CROWN_PLATFORM_WINDOWS
+		return strlen(path) > 2 && isalpha(path[0]) && path[1] == ':' && path[2] == '\\';
+#endif
+	}
+
+	bool is_root_path(const char* path)
+	{
+		CE_ASSERT(path != NULL, "Path must be != NULL");
+#if CROWN_PLATFORM_POSIX
+		return is_absolute_path(path) && strlen(path) == 1;
+#elif CROWN_PLATFORM_WINDOWS
+		return is_absolute_path(path) && strlen(path) == 3;
+#endif
+	}
+
 	/// Returns the pathname of the path.
 	/// @note
 	/// e.g. "/home/project/texture.tga" -> "/home/project"

+ 4 - 1
engine/core/strings/path.h

@@ -31,9 +31,12 @@ namespace path
 	/// Returns whether @a path is valid.
 	bool is_valid_path(const char* path);
 
-	/// Returns whether the path @a path is absolute.
+	/// Returns whether the @a path is absolute.
 	bool is_absolute_path(const char* path);
 
+	/// Returns whether the @a path is the root path.
+	bool is_root_path(const char* path);
+
 	void pathname(const char* path, char* str, size_t len);
 	void filename(const char* path, char* str, size_t len);
 	void basename(const char* path, char* str, size_t len);