684a480fb2631f26f0ae454becce433e39c89b95
[cvc5.git] / src / util / regexp.cpp
1 /********************* */
2 /*! \file regexp.cpp
3 ** \verbatim
4 ** Original author: Tianyi Liang
5 ** Major contributors: none
6 ** Minor contributors (to current version): Morgan Deters
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
11 **
12 ** \brief [[ Add one-line brief description here ]]
13 **
14 ** [[ Add lengthier description here ]]
15 ** \todo document this file
16 **/
17
18 #include "util/regexp.h"
19 #include <iostream>
20 #include <iomanip>
21
22 using namespace std;
23
24 namespace CVC4 {
25
26 std::string String::toString() const {
27 std::string str;
28 for(unsigned int i=0; i<d_str.size(); ++i) {
29 char c = convertUnsignedIntToChar( d_str[i] );
30 if(isprint( c )) {
31 if(c == '\\') {
32 str += "\\\\";
33 } else if(c == '\"') {
34 str += "\\\"";
35 } else {
36 str += c;
37 }
38 } else {
39 std::string s;
40 switch(c) {
41 case '\a': s = "\\a"; break;
42 case '\b': s = "\\b"; break;
43 case '\t': s = "\\t"; break;
44 case '\r': s = "\\r"; break;
45 case '\v': s = "\\v"; break;
46 case '\f': s = "\\f"; break;
47 case '\n': s = "\\n"; break;
48 case '\e': s = "\\e"; break;
49 default : {
50 std::stringstream ss;
51 ss << std::setfill ('0') << std::setw(2) << std::hex << ((int)c);
52 s = "\\x" + ss.str();
53 //std::string s2 = static_cast<std::ostringstream*>( &(std::ostringstream() << (int)c) )->str();
54 }
55 }
56 str += s;
57 }
58 }
59 return str;
60 }
61
62 std::ostream& operator <<(std::ostream& os, const String& s) {
63 return os << "\"" << s.toString() << "\"";
64 }
65
66 std::ostream& operator<<(std::ostream& out, const RegExp& s) {
67 return out << "regexp(" << s.getType() << ')';
68 }
69
70 }/* CVC4 namespace */