cmake: Disable C++ GNU extensions. (#3446)
[cvc5.git] / src / util / smt2_quote_string.cpp
1 /********************* */
2 /*! \file smt2_quote_string.cpp
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Tim King, Morgan Deters, Kshitij Bansal
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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.\endverbatim
11 **
12 ** \brief Quotes a string if necessary for smt2.
13 **
14 ** Quotes a string if necessary for smt2.
15 **/
16
17 #include "util/smt2_quote_string.h"
18
19 #include <string>
20
21 namespace CVC4 {
22
23 /**
24 * SMT-LIB 2 quoting for symbols
25 */
26 std::string quoteSymbol(const std::string& s){
27 if(s.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@$%^&*_-+=<>.?/") == std::string::npos) {
28 // simple unquoted symbol
29 return s;
30 } else {
31 std::string tmp(s);
32 // must quote the symbol, but it cannot contain | or \, we turn those into _
33 size_t p;
34 while((p = tmp.find_first_of("\\|")) != std::string::npos) {
35 tmp = tmp.replace(p, 1, "_");
36 }
37 return "|" + tmp + "|";
38 }
39 }
40
41 }/* CVC4 namespace */