python: implement formula.__format__
Fixes #105. * src/bin/common_trans.cc (quote_shell_string): Move ... * src/misc/escape.cc, src/misc/escape.hh (quote_shell_string): ... here. * wrap/python/spot_impl.i: Wrap escape.hh. * wrap/python/spot.py: Implement formula.__format__. * wrap/python/tests/ltlsimple.py: Test it. * NEWS, doc/org/tut01.org, wrap/python/tests/formulas.ipynb: Document it.
This commit is contained in:
parent
20bb171904
commit
5bfd0267e7
9 changed files with 364 additions and 67 deletions
|
|
@ -27,6 +27,7 @@
|
|||
#include <functional>
|
||||
#include <cctype>
|
||||
#include <locale>
|
||||
#include <cstring>
|
||||
#include "escape.hh"
|
||||
|
||||
namespace spot
|
||||
|
|
@ -143,4 +144,35 @@ namespace spot
|
|||
std::find_if(str.begin(), str.end(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
quote_shell_string(std::ostream& os, const char* str)
|
||||
{
|
||||
// Single quotes are best, unless the string to quote contains one.
|
||||
if (!strchr(str, '\''))
|
||||
{
|
||||
os << '\'' << str << '\'';
|
||||
}
|
||||
else
|
||||
{
|
||||
// In double quotes we have to escape $ ` " or \.
|
||||
os << '"';
|
||||
while (*str)
|
||||
switch (*str)
|
||||
{
|
||||
case '$':
|
||||
case '`':
|
||||
case '"':
|
||||
case '\\':
|
||||
os << '\\';
|
||||
// fall through
|
||||
default:
|
||||
os << *str++;
|
||||
break;
|
||||
}
|
||||
os << '"';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue