1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Tim King, Andres Noetzli, Morgan Deters |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Quotes a string if necessary for smt2. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "util/smt2_quote_string.h" |
17 |
|
|
18 |
|
#include <sstream> |
19 |
|
#include <string> |
20 |
|
|
21 |
|
namespace cvc5 { |
22 |
|
|
23 |
|
/** |
24 |
|
* SMT-LIB 2 quoting for symbols |
25 |
|
*/ |
26 |
840423 |
std::string quoteSymbol(const std::string& s){ |
27 |
|
// this is the set of SMT-LIBv2 permitted characters in "simple" (non-quoted) |
28 |
|
// symbols |
29 |
1680846 |
if (s.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
30 |
|
"0123456789~!@$%^&*_-+=<>.?/") |
31 |
|
!= std::string::npos |
32 |
840423 |
|| s.empty() || (s[0] >= '0' && s[0] <= '9')) |
33 |
|
{ |
34 |
444174 |
std::string tmp(s); |
35 |
|
// must quote the symbol, but it cannot contain | or \, we turn those into _ |
36 |
|
size_t p; |
37 |
225227 |
while((p = tmp.find_first_of("\\|")) != std::string::npos) { |
38 |
1570 |
tmp = tmp.replace(p, 1, "_"); |
39 |
|
} |
40 |
222087 |
return "|" + tmp + "|"; |
41 |
|
} |
42 |
618336 |
return s; |
43 |
|
} |
44 |
|
|
45 |
|
} // namespace cvc5 |