mirror of
https://github.com/reactos/CMake.git
synced 2024-11-25 04:29:52 +00:00
ENH: Added Split method to cmSystemTools to split a string into lines on its newlines.
This commit is contained in:
parent
3d3d7a9146
commit
a8d038dbd0
@ -1894,6 +1894,34 @@ std::string cmSystemTools::CollapseFullPath(const char* in_name)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmSystemTools::Split(const char* str, std::vector<cmStdString>& lines)
|
||||||
|
{
|
||||||
|
std::string data(str);
|
||||||
|
std::string::size_type lpos = 0;
|
||||||
|
while(lpos < data.length())
|
||||||
|
{
|
||||||
|
std::string::size_type rpos = data.find_first_of("\n", lpos);
|
||||||
|
if(rpos == std::string::npos)
|
||||||
|
{
|
||||||
|
// Line ends at end of string without a newline.
|
||||||
|
lines.push_back(data.substr(lpos));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if((rpos > lpos) && (data[rpos-1] == '\r'))
|
||||||
|
{
|
||||||
|
// Line ends in a "\r\n" pair, remove both characters.
|
||||||
|
lines.push_back(data.substr(lpos, (rpos-1)-lpos));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Line ends in a "\n", remove the character.
|
||||||
|
lines.push_back(data.substr(lpos, rpos-lpos));
|
||||||
|
}
|
||||||
|
lpos = rpos+1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return path of a full filename (no trailing slashes).
|
* Return path of a full filename (no trailing slashes).
|
||||||
* Warning: returned path is converted to Unix slashes format.
|
* Warning: returned path is converted to Unix slashes format.
|
||||||
|
@ -218,11 +218,11 @@ public:
|
|||||||
|
|
||||||
///! Find a file in the system PATH, with optional extra paths.
|
///! Find a file in the system PATH, with optional extra paths.
|
||||||
static std::string FindFile(const char* name,
|
static std::string FindFile(const char* name,
|
||||||
const std::vector<std::string>& path= std::vector<std::string>());
|
const std::vector<std::string>& path= std::vector<std::string>());
|
||||||
|
|
||||||
///! Find an executable in the system PATH, with optional extra paths.
|
///! Find an executable in the system PATH, with optional extra paths.
|
||||||
static std::string FindProgram(const char* name,
|
static std::string FindProgram(const char* name,
|
||||||
const std::vector<std::string>& path = std::vector<std::string>(),
|
const std::vector<std::string>& path = std::vector<std::string>(),
|
||||||
bool no_system_path = false);
|
bool no_system_path = false);
|
||||||
|
|
||||||
///! Find a library in the system PATH, with optional extra paths.
|
///! Find a library in the system PATH, with optional extra paths.
|
||||||
@ -293,6 +293,10 @@ public:
|
|||||||
static void EnableRunCommandOutput() {s_DisableRunCommandOutput = false; }
|
static void EnableRunCommandOutput() {s_DisableRunCommandOutput = false; }
|
||||||
static bool GetRunCommandOutput() { return s_DisableRunCommandOutput; }
|
static bool GetRunCommandOutput() { return s_DisableRunCommandOutput; }
|
||||||
|
|
||||||
|
/** Split a string on its newlines into multiple lines. Returns
|
||||||
|
false only if the last line stored had no newline. */
|
||||||
|
static bool Split(const char* str, std::vector<cmStdString>& lines);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Come constants for different file formats.
|
* Come constants for different file formats.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user