mirror of
https://github.com/GothenburgBitFactory/taskshell.git
synced 2025-06-26 10:54:29 +02:00
Text: Added more polymorphic formatters
This commit is contained in:
parent
86687adb97
commit
b794da1cc9
2 changed files with 23 additions and 0 deletions
21
src/text.cpp
21
src/text.cpp
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <strings.h>
|
||||
|
@ -110,6 +111,14 @@ bool closeEnough (
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string format (int value)
|
||||
{
|
||||
std::stringstream s;
|
||||
s << value;
|
||||
return s.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void replace_positional (
|
||||
std::string& fmt,
|
||||
|
@ -135,3 +144,15 @@ const std::string format (
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string format (
|
||||
const std::string& fmt,
|
||||
int arg1,
|
||||
int arg2)
|
||||
{
|
||||
std::string output = fmt;
|
||||
replace_positional (output, "{1}", format (arg1));
|
||||
replace_positional (output, "{2}", format (arg2));
|
||||
return output;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -37,7 +37,9 @@ void split (std::vector<std::string>&, const std::string&, const char);
|
|||
std::string lowerCase (const std::string&);
|
||||
bool compare (const std::string&, const std::string&, bool sensitive = true);
|
||||
bool closeEnough (const std::string&, const std::string&, unsigned int minLength = 0);
|
||||
const std::string format (int);
|
||||
const std::string format (const std::string&, const std::string&);
|
||||
const std::string format (const std::string&, int, int);
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue