From eb886d0c458915ce6b6e9c1911c85d3beb0093c2 Mon Sep 17 00:00:00 2001 From: blahpy Date: Wed, 9 Sep 2020 16:54:16 +1200 Subject: [PATCH] Upload new files --- CMakeLists.txt | 3 +++ common/util/CMakeLists.txt | 5 +++++ common/util/FileUtil.cpp | 26 ++++++++++++++++++++++++++ common/util/FileUtil.h | 11 +++++++++++ test/CMakeLists.txt | 2 +- test/test_common_util.cpp | 11 +++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 common/util/CMakeLists.txt create mode 100644 common/util/FileUtil.cpp create mode 100644 common/util/FileUtil.h create mode 100644 test/test_common_util.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b40377dc4a..11066c5f43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,9 @@ add_subdirectory(asset_tool) # build type_system library for compiler/decompiler add_subdirectory(common/type_system) +# build common_util library +add_subdirectory(common/util) + # build decompiler add_subdirectory(decompiler) diff --git a/common/util/CMakeLists.txt b/common/util/CMakeLists.txt new file mode 100644 index 0000000000..d6434a56b8 --- /dev/null +++ b/common/util/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(common_util + SHARED + FileUtil.cpp) + +target_link_libraries(common_util fmt) \ No newline at end of file diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp new file mode 100644 index 0000000000..e6f19d6b4d --- /dev/null +++ b/common/util/FileUtil.cpp @@ -0,0 +1,26 @@ +#include "FileUtil.h" +#include +#include + +std::string FileUtil::get_file_path(std::string input[]) { + int arrSize = std::sizeof(input); + std::string currentPath = std::filesystem::current_path(); + char dirSeparator; + + #ifdef _WIN32 + dirSeparator = '\'; + #else + dirSeparator = '/'; + #endif + + std::string filePath = currentPath; + for (int i = 0; i < arrSize; i++) { + if (arrSize = i+1) { + filePath = filePath << input[i]; + } else { + filePath = filePath << input[i] << dirSeparator; + } + } + + return filePath; +} \ No newline at end of file diff --git a/common/util/FileUtil.h b/common/util/FileUtil.h new file mode 100644 index 0000000000..925cd3d017 --- /dev/null +++ b/common/util/FileUtil.h @@ -0,0 +1,11 @@ +#pragma once +#include + +namespace FileUtil +{ + class FileUtil + { + public: + std::string get_file_path(); + }; +} \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8173c9820c..1b8a271300 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,7 +14,7 @@ add_executable(goalc-test test_emitter_loads_and_store.cpp test_emitter_xmm32.cpp test_emitter_integer_math.cpp - ) + "test_common_util.cpp") IF (WIN32) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) diff --git a/test/test_common_util.cpp b/test/test_common_util.cpp new file mode 100644 index 0000000000..02a3985f6f --- /dev/null +++ b/test/test_common_util.cpp @@ -0,0 +1,11 @@ +#include "common/util/FileUtil.h" +#include +#include "gtest/gtest.h" + +TEST(test, test) { + + std::string test[] = {"cabbage", "banana", "apple"}; + std::cout << FileUtil::get_file_path(test) << std::endl; + + EXPECT_TRUE(true); +} \ No newline at end of file