diff options
Diffstat (limited to 'apps/cassiopeia/src/format/ir.rs')
-rw-r--r-- | apps/cassiopeia/src/format/ir.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/apps/cassiopeia/src/format/ir.rs b/apps/cassiopeia/src/format/ir.rs index 32922ec079e7..09a54e810615 100644 --- a/apps/cassiopeia/src/format/ir.rs +++ b/apps/cassiopeia/src/format/ir.rs @@ -44,7 +44,7 @@ pub(crate) fn generate_ir(buf: impl Iterator<Item = LineCfg>) -> IrStream { buf.enumerate().fold(vec![], |mut buf, (lo, item)| { #[cfg_attr(rustfmt, rustfmt_skip)] buf.push(match item { - LineCfg::Header(map) => IrItem { tt: IrType::Header(map), lo }, + LineCfg::Header(map) => IrItem { tt: IrType::Header(map.into_iter().map(|(k, v)| (k, v.replace(",", ""))).collect()), lo }, LineCfg::Start(Some(time)) => IrItem { tt: IrType::Start(time.into()), lo }, LineCfg::Stop(Some(time)) => IrItem { tt: IrType::Stop(time.into()), lo }, LineCfg::Invoice(Some(date)) => IrItem { tt: IrType::Invoice(date.into()), lo }, @@ -56,8 +56,45 @@ pub(crate) fn generate_ir(buf: impl Iterator<Item = LineCfg>) -> IrStream { }) } - pub(crate) trait MakeIr { /// Make a new IR line from an object fn make_ir(&self) -> IrType; } + +pub(crate) fn clean_ir(ir: &mut IrStream) { + ir.remove(0); // FIXME: this is required to remove the leading + // comment, which will be manually re-generated at + // the moment, but which would just add more blank + // lines between the new comment, and the first line + // in this current format. This is very bad, yikes + // yikes yikes, but what can I do, I have a deadline + // (not really) lol + + // FIXME: this hack gets rid of a trailing empty line if it exists + // to make sure we don't have any gaps between work sessions. + if match ir.last() { + Some(IrItem { + tt: IrType::Ignore, .. + }) => true, + _ => false, + } { + ir.pop(); + } +} + +/// Taken an IrType and append it to an existing IR stream +pub(crate) fn append_ir(ir: &mut IrStream, tt: IrType) { + + let lo = ir.last().unwrap().lo; + ir.push(IrItem { tt, lo }); +} + +/// Search for the header that contains the version string and update it +pub(crate) fn update_header(ir: &mut IrStream) { + ir.iter_mut().for_each(|item| match item.tt { + IrType::Header(ref mut map) if map.contains_key("version") => { + map.insert("version".into(), crate::meta::VERSION.into()); + } + _ => {} + }); +} |