mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
util: Added ::quoteIfNeeded
This commit is contained in:
parent
f50b3b4fc2
commit
ebf9234006
2 changed files with 24 additions and 0 deletions
|
@ -41,5 +41,6 @@ int dispatchCommand (const std::vector <std::string>&, Database&, Rules&, Extens
|
||||||
// utiŀ.cpp
|
// utiŀ.cpp
|
||||||
std::string osName ();
|
std::string osName ();
|
||||||
std::string escape (const std::string&, int);
|
std::string escape (const std::string&, int);
|
||||||
|
std::string quoteIfNeeded (const std::string&);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
23
src/util.cpp
23
src/util.cpp
|
@ -25,6 +25,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
|
#include <timew.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -79,3 +80,25 @@ std::string escape (const std::string& input, int c)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::string quoteIfNeeded (const std::string& input)
|
||||||
|
{
|
||||||
|
auto quote = input.find ('"');
|
||||||
|
auto space = input.find (' ');
|
||||||
|
|
||||||
|
if (quote == std::string::npos &&
|
||||||
|
space == std::string::npos)
|
||||||
|
return input;
|
||||||
|
|
||||||
|
std::string output;
|
||||||
|
if (quote != std::string::npos)
|
||||||
|
output = escape (input, '"');
|
||||||
|
else
|
||||||
|
output = input;
|
||||||
|
|
||||||
|
if (space != std::string::npos)
|
||||||
|
output = std::string ("\"") + output + "\"";
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue