From 4e3c5e21f53184c2b4f55a33d5fc8ab7b0fe05fe Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 14:19:08 -0500 Subject: [PATCH] fixed top-level keys --- src/main.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1ea05ac..fc449f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,20 +40,26 @@ fn main() { } else { content = input.to_string(); } let mut tabkey: Vec<&str> = arguments[0].split(".").collect(); - let mut indexvec: Vec<&str> = tabkey[1].split(&['[', ']'][..]).collect(); - - tabkey[1] = indexvec.remove(0); + let mut indexvec = Vec::new(); let mut index: usize = 0; - if ! indexvec.is_empty() { - let istr = indexvec.remove(0); - match usize::from_str(istr) { - Ok(i) => index = i, - Err(_) => { - eprintln!("{}: {}: Cannot index by given value.", argv0, istr); - process::exit(65); // sysexits(3) EX_DATAERR - }, - }; - } + + match tabkey.iter().skip(1).peekable().peek() { + Some(_) => { + indexvec = tabkey[1].split(&['[', ']'][..]).collect(); + tabkey[1] = indexvec.remove(0); + if ! indexvec.is_empty() { + let istr = indexvec.remove(0); + match usize::from_str(istr) { + Ok(i) => index = i, + Err(_) => { + eprintln!("{}: {}: Cannot index by given value.", argv0, istr); + process::exit(65); // sysexits(3) EX_DATAERR + }, + }; + } + }, + None => {}, + }; let mut root = content.parse::().unwrap();