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

Line Exec Source
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
751877
std::string quoteSymbol(const std::string& s){
27
  // this is the set of SMT-LIBv2 permitted characters in "simple" (non-quoted)
28
  // symbols
29
1503754
  if (s.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
30
                          "0123456789~!@$%^&*_-+=<>.?/")
31
          != std::string::npos
32
751877
      || s.empty() || (s[0] >= '0' && s[0] <= '9'))
33
  {
34
385370
    std::string tmp(s);
35
    // must quote the symbol, but it cannot contain | or \, we turn those into _
36
    size_t p;
37
196149
    while((p = tmp.find_first_of("\\|")) != std::string::npos) {
38
1732
      tmp = tmp.replace(p, 1, "_");
39
    }
40
192685
    return "|" + tmp + "|";
41
  }
42
559192
  return s;
43
}
44
45
}  // namespace cvc5