<rdar://problem/13926101>

Allow “command script import” to work with folder names that have a ‘ (tick) in them

Kudos to StackOverflow (question 1494399) for the replace_all code!

llvm-svn: 184158
This commit is contained in:
Enrico Granata 2013-06-18 00:58:06 +00:00
parent de5fde0b05
commit 9b27c6f0d4
1 changed files with 17 additions and 3 deletions

View File

@ -2577,6 +2577,19 @@ ReadPythonBacktrace (PyObject* py_backtrace)
return retval;
}
uint64_t replace_all(std::string& str, const std::string& oldStr, const std::string& newStr)
{
size_t pos = 0;
uint64_t matches = 0;
while((pos = str.find(oldStr, pos)) != std::string::npos)
{
matches++;
str.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
}
return matches;
}
bool
ScriptInterpreterPython::LoadScriptingModule (const char* pathname,
bool can_reload,
@ -2624,13 +2637,14 @@ ScriptInterpreterPython::LoadScriptingModule (const char* pathname,
target_file.GetFileType() == FileSpec::eFileTypeRegular ||
target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink)
{
const char* directory = target_file.GetDirectory().GetCString();
std::string directory(target_file.GetDirectory().GetCString());
replace_all(directory,"'","\\'");
// now make sure that Python has "directory" in the search path
StreamString command_stream;
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
directory,
directory);
directory.c_str(),
directory.c_str());
bool syspath_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
if (!syspath_retval)
{