about summary refs log tree commit diff
path: root/src/facility
diff options
context:
space:
mode:
Diffstat (limited to 'src/facility')
-rw-r--r--src/facility/i3.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/facility/i3.rs b/src/facility/i3.rs
index d914548..53258f8 100644
--- a/src/facility/i3.rs
+++ b/src/facility/i3.rs
@@ -530,3 +530,27 @@ fn parse_success_object(json: &[u8]) -> Result<bool> {
   }
 }
 
+
+pub fn parse_change_string(json: &[u8]) -> Result<String> {
+  let mut parser = SliceJsonParser::new(json);
+
+  if let JsonEvent::StartObject = parser.parse_next()? { } else {
+    return Err(Error::custom("Reading i3 JSON, expected object start."));
+  }
+
+  if let JsonEvent::ObjectKey(key) = parser.parse_next()? {
+    if key == "change" {
+      if let JsonEvent::String(result) = parser.parse_next()? {
+        /* That's our answer; exit early. */
+        return Ok(result.into_owned());
+      } else {
+        return Err(Error::custom("Reading i3 JSON, expected string."));
+      }
+    } else {
+      return Err(Error::custom("Reading i3 JSON, expected \"change\" key."));
+    }
+  } else {
+    return Err(Error::custom("Reading i3 JSON, expected object key."));
+  }
+}
+