GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/smt2_quote_string.cpp Lines: 8 8 100.0 %
Date: 2021-03-23 Branches: 17 22 77.3 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file smt2_quote_string.cpp
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Tim King, Andres Noetzli, Morgan Deters
6
 ** This file is part of the CVC4 project.
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.\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 <sstream>
20
#include <string>
21
22
namespace CVC4 {
23
24
/**
25
 * SMT-LIB 2 quoting for symbols
26
 */
27
724044
std::string quoteSymbol(const std::string& s){
28
  // this is the set of SMT-LIBv2 permitted characters in "simple" (non-quoted)
29
  // symbols
30
1448088
  if (s.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
31
                          "0123456789~!@$%^&*_-+=<>.?/")
32
          != std::string::npos
33
724044
      || s.empty() || (s[0] >= '0' && s[0] <= '9'))
34
  {
35
368676
    std::string tmp(s);
36
    // must quote the symbol, but it cannot contain | or \, we turn those into _
37
    size_t p;
38
187802
    while((p = tmp.find_first_of("\\|")) != std::string::npos) {
39
1732
      tmp = tmp.replace(p, 1, "_");
40
    }
41
184338
    return "|" + tmp + "|";
42
  }
43
539706
  return s;
44
}
45
46
}/* CVC4 namespace */