diff src/c/urweb.c @ 1992:7075acda4456

Parse new bytea output format from Postgres 9.x
author Adam Chlipala <adam@chlipala.net>
date Tue, 25 Feb 2014 16:34:04 -0500
parents 819756825c8d
children 3d1d44111906
line wrap: on
line diff
--- a/src/c/urweb.c	Thu Feb 20 15:50:33 2014 -0500
+++ b/src/c/urweb.c	Tue Feb 25 16:34:04 2014 -0500
@@ -3049,27 +3049,39 @@
 
   uw_check_heap(ctx, len);
 
-  while (*s) {
-    if (s[0] == '\\') {
-      if (s[1] == '\\') {
-        *r++ = '\\';
-        s += 2;
-      } else if (isdigit((int)s[1]) && isdigit((int)s[2]) && isdigit((int)s[3])) {
-        *r++ = (s[1] - '0') * 8 * 8 + ((s[2] - '0') * 8) + (s[3] - '0');
-        s += 4;
-      }
-      else {
-        *r++ = '\\';
+  if (s[0] == '\\' && s[1] == 'x') {
+    s += 2;
+
+    while (*s) {
+      int n;
+      sscanf(s, "%02x", &n);
+      *r++ = n;
+      s += 2;
+    }
+  } else {
+    while (*s) {
+      if (s[0] == '\\') {
+        if (s[1] == '\\') {
+          *r++ = '\\';
+          s += 2;
+        } else if (isdigit((int)s[1]) && isdigit((int)s[2]) && isdigit((int)s[3])) {
+          *r++ = (s[1] - '0') * 8 * 8 + ((s[2] - '0') * 8) + (s[3] - '0');
+          s += 4;
+        }
+        else {
+          *r++ = '\\';
+          ++s;
+        }
+      } else {
+        *r++ = s[0];
         ++s;
       }
-    } else {
-      *r++ = s[0];
-      ++s;
     }
   }
 
   b.size = r - ctx->heap.front;
   ctx->heap.front = r;
+
   return b;
 }