Skip to content

Commit 2093dfa

Browse files
authored
use non-filesystem based way to get function name (#358)
* use non-filesystem based way to get function name * update test * better test
1 parent 411b786 commit 2093dfa

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

co_sim_io/sources/code_location.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,34 @@
1414

1515
// Project includes
1616
#include "includes/code_location.hpp"
17-
#include "includes/filesystem_inc.hpp"
1817

1918
namespace CoSimIO {
2019
namespace Internals {
2120

2221
std::string CodeLocation::GetCleanFileName() const
2322
{
24-
return fs::canonical(fs::path(GetFileName())).lexically_relative(fs::absolute(".")).string();
23+
std::string clean_file_name(GetFileName());
24+
25+
// Replace all backslashes with forward slashes
26+
std::size_t start_position = 0;
27+
const std::string from_string = "\\";
28+
const std::string to_string = "/";
29+
while ((start_position = clean_file_name.find(from_string, start_position)) != std::string::npos) {
30+
clean_file_name.replace(start_position, from_string.length(), to_string);
31+
start_position += to_string.length();
32+
}
33+
34+
// Remove the path up to the co_sim_io root folder
35+
std::size_t co_sim_io_root_position = clean_file_name.rfind("/co_sim_io/");
36+
if (co_sim_io_root_position != std::string::npos) {
37+
clean_file_name.erase(0, co_sim_io_root_position+1);
38+
return clean_file_name;
39+
}
40+
if (co_sim_io_root_position != std::string::npos) {
41+
clean_file_name.erase(0, co_sim_io_root_position + 1 );
42+
}
43+
44+
return clean_file_name;
2545
}
2646

2747
} // namespace Internals

co_sim_io/sources/version.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int GetMinorVersion() {
2424
}
2525

2626
std::string GetPatchVersion() {
27-
return "0";
27+
return "1";
2828
}
2929

3030
} // namespace CoSimIO

tests/co_sim_io/cpp/test_code_location.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TEST_SUITE("CodeLocation") {
3333
TEST_CASE("macro_CO_SIM_IO_CODE_LOCATION")
3434
{
3535
auto code_loc = testing_aux_namespace::AuxFunction();
36-
CHECK_MESSAGE(code_loc.GetCleanFileName().find(fs::path("co_sim_io/cpp/test_code_location.cpp").make_preferred().string()) != std::string::npos, code_loc.GetCleanFileName()); // must contain at least this
36+
CHECK_EQ("co_sim_io/cpp/test_code_location.cpp", code_loc.GetCleanFileName());
3737
CHECK_EQ(code_loc.GetLineNumber(), 25);
3838
CHECK_MESSAGE(code_loc.GetCleanFunctionName().find("testing_aux_namespace::AuxFunction") != std::string::npos, code_loc.GetCleanFunctionName()); // must contain at least this
3939
}

0 commit comments

Comments
 (0)