Skip to content

Commit 545f0ea

Browse files
Simplify include path handling and support cross-platform path delimiters
- Simplified the include path processing logic by reducing unnecessary braces. - Improved cross-platform compatibility by correctly handling non-standard path separators on Windows and Unix systems. - Combined the default include path addition and environment variable parsing into a more concise and efficient implementation.
1 parent bdb66eb commit 545f0ea

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/xinterpreter.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "xeus-cpp/xinterpreter.hpp"
1616
#include "xeus-cpp/xmagics.hpp"
1717

18+
#include <cstdlib> // for std::getenv
1819
#include <cstring> // for std::strlen
1920
#include <sstream> // for std::istringstream
2021
#include <string> // for std::getline
@@ -364,25 +365,23 @@ __get_cxx_version ()
364365
// Add the standard include path
365366
Cpp::AddIncludePath((xeus::prefix_path() + "/include/").c_str());
366367

367-
// Get include paths from environment variable
368+
// Get include paths from environment variable and use empty string if not set
368369
const char* non_standard_paths = std::getenv("XEUS_SEARCH_PATH");
369-
if (!non_standard_paths) {
370+
if (!non_standard_paths)
370371
non_standard_paths = "";
371-
}
372372

373-
if (std::strlen(non_standard_paths) > 0)
374-
{
375-
// Split the paths by colon ':' and add each one
376-
std::istringstream stream(non_standard_paths);
377-
std::string path;
378-
while (std::getline(stream, path, ':'))
379-
{
380-
if (!path.empty())
381-
{
382-
Cpp::AddIncludePath(path.c_str());
383-
}
384-
}
385-
}
373+
#ifdef _WIN32
374+
const char path_separator = ';';
375+
#else
376+
const char path_separator = ':';
377+
#endif
378+
379+
// Split and add each non-empty path
380+
std::istringstream stream(non_standard_paths);
381+
std::string path;
382+
while (std::getline(stream, path, path_separator))
383+
if (!path.empty())
384+
Cpp::AddIncludePath(path.c_str());
386385
}
387386

388387
void interpreter::init_preamble()

0 commit comments

Comments
 (0)