From 0727fca7978e1f4884a22cbcfb9f6615b021e2d4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Feb 2016 11:44:22 +0100 Subject: [PATCH] Add tokenizer helper function --- libimagstore/src/store.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 2157c19e..e5d6e9b2 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -320,6 +320,12 @@ pub struct EntryHeader { pub type EntryResult = RResult; +#[derive(Debug, Clone, PartialEq, Eq)] +enum Token { + Key(String), + Index(usize), +} + /** * Wrapper type around file header (TOML) object */ @@ -440,6 +446,19 @@ impl EntryHeader { pub fn read(&self, spec: &str) -> Result> { unimplemented!() } + + fn tokenize(spec: &str) -> Result> { + use std::str::FromStr; + + spec.split(".") + .map(|s| { + usize::from_str(s) + .map(Token::Index) + .or_else(|_| Ok(Token::Key(String::from(s)))) + }) + .collect() + } + } fn build_default_header() -> BTreeMap {