add a new file
authorTianyi Liang <tianyi-liang@uiowa.edu>
Wed, 26 Feb 2014 17:43:59 +0000 (11:43 -0600)
committerTianyi Liang <tianyi-liang@uiowa.edu>
Wed, 26 Feb 2014 17:43:59 +0000 (11:43 -0600)
src/util/regexp.cpp [new file with mode: 0644]

diff --git a/src/util/regexp.cpp b/src/util/regexp.cpp
new file mode 100644 (file)
index 0000000..246f162
--- /dev/null
@@ -0,0 +1,70 @@
+/*********************                                                        */\r
+/*! \file regexp.cpp\r
+ ** \verbatim\r
+ ** Original author: Tianyi Liang\r
+ ** Major contributors: none\r
+ ** Minor contributors (to current version): Morgan Deters\r
+ ** This file is part of the CVC4 project.\r
+ ** Copyright (c) 2009-2013  New York University and The University of Iowa\r
+ ** See the file COPYING in the top-level source directory for licensing\r
+ ** information.\endverbatim\r
+ **\r
+ ** \brief [[ Add one-line brief description here ]]\r
+ **\r
+ ** [[ Add lengthier description here ]]\r
+ ** \todo document this file\r
+ **/\r
+\r
+#include "util/regexp.h"\r
+#include <iostream>\r
+\r
+using namespace std;\r
+\r
+namespace CVC4 {\r
+\r
+std::string String::toString() const {\r
+       std::string str;\r
+       for(unsigned int i=0; i<d_str.size(); ++i) {\r
+         char c = convertUnsignedIntToChar( d_str[i] );\r
+         if(isprint( c )) {\r
+               if(c == '\\') {\r
+                       str += "\\\\";\r
+               } else if(c == '\"') {\r
+                       str += "\\\"";\r
+               } else {\r
+                       str += c;\r
+               }\r
+         } else {\r
+                 std::string s;\r
+                 switch(c) {\r
+                       case '\a': s = "\\a"; break;\r
+                       case '\b': s = "\\b"; break;\r
+                       case '\t': s = "\\t"; break;\r
+                       case '\r': s = "\\r"; break;\r
+                       case '\v': s = "\\v"; break;\r
+                       case '\f': s = "\\f"; break;\r
+                       case '\n': s = "\\n"; break;\r
+                       case '\e': s = "\\e"; break;\r
+                       default  : {\r
+                               std::string s2 = static_cast<std::ostringstream*>( &(std::ostringstream() << (int)c) )->str();\r
+                               if(s2.size() == 1) {\r
+                                       s2 = "0" + s2;\r
+                               }\r
+                               s = "\\x" + s2;\r
+                       }\r
+                 }\r
+                 str += s;\r
+         }\r
+       }\r
+       return str;\r
+}\r
+\r
+std::ostream& operator <<(std::ostream& os, const String& s) {\r
+  return os << "\"" << s.toString() << "\"";\r
+}\r
+\r
+std::ostream& operator<<(std::ostream& out, const RegExp& s) {\r
+  return out << "regexp(" << s.getType() << ')';\r
+}\r
+\r
+}/* CVC4 namespace */
\ No newline at end of file