about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-04-19T13·46+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-04-19T13·46+0000
commitefc7a579e880ec15ebe9afc0d8766c85c7d53ec2 (patch)
treec83d553fcdc3f3497b6645baa198288d499054a1 /src/libutil/util.cc
parent55b5ddd3ca1ff4dfe4cfbfab92a4025d88ef6443 (diff)
* Don't use the ATerm library for parsing/printing .drv files.
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index d28d0e823c05..98912e7a002c 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1006,6 +1006,47 @@ bool hasSuffix(const string & s, const string & suffix)
 }
 
 
+void expect(std::istream & str, const string & s)
+{
+    char s2[s.size()];
+    str.read(s2, s.size());
+    if (string(s2, s.size()) != s)
+        throw Error(format("expected string `%1%'") % s);
+}
+
+
+string parseString(std::istream & str)
+{
+    string res;
+    expect(str, "\"");
+    int c;
+    while ((c = str.get()) != '"')
+        if (c == '\\') {
+            c = str.get();
+            if (c == 'n') res += '\n';
+            else if (c == 'r') res += '\r';
+            else if (c == 't') res += '\t';
+            else res += c;
+        }
+        else res += c;
+    return res;
+}
+
+
+bool endOfList(std::istream & str)
+{
+    if (str.peek() == ',') {
+        str.get();
+        return false;
+    }
+    if (str.peek() == ']') {
+        str.get();
+        return true;
+    }
+    return false;
+}
+
+
 void ignoreException()
 {
     try {