From 36b3067c19c8743032a44f888ee48702b88d135b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 10 Jul 2021 13:07:39 +0200 Subject: =?UTF-8?q?Eco=20string=20=F0=9F=8C=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/exec/context.rs | 5 +++-- src/exec/mod.rs | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/exec') diff --git a/src/exec/context.rs b/src/exec/context.rs index 0f6d47f5..4764a808 100644 --- a/src/exec/context.rs +++ b/src/exec/context.rs @@ -3,6 +3,7 @@ use std::rc::Rc; use super::{Exec, ExecWithMap, FontFamily, State}; use crate::diag::{Diag, DiagSet, Pass}; +use crate::eco::EcoString; use crate::eval::{ExprMap, TemplateValue}; use crate::geom::{Align, Dir, Gen, GenAxis, Length, Linear, Sides, Size}; use crate::layout::{ @@ -77,7 +78,7 @@ impl ExecContext { /// Push text into the active paragraph. /// /// The text is split into lines at newlines. - pub fn push_text(&mut self, text: impl Into) { + pub fn push_text(&mut self, text: impl Into) { self.stack.par.push(self.make_text_node(text)); } @@ -143,7 +144,7 @@ impl ExecContext { Pass::new(self.tree, self.diags) } - fn make_text_node(&self, text: impl Into) -> ParChild { + fn make_text_node(&self, text: impl Into) -> ParChild { ParChild::Text( text.into(), self.state.aligns.cross, diff --git a/src/exec/mod.rs b/src/exec/mod.rs index fc829676..2a145fbc 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -6,6 +6,7 @@ mod state; pub use context::*; pub use state::*; +use std::fmt::Write; use std::rc::Rc; use crate::diag::Pass; @@ -13,6 +14,7 @@ use crate::eval::{ExprMap, TemplateFunc, TemplateNode, TemplateValue, Value}; use crate::geom::{Dir, Gen}; use crate::layout::{LayoutTree, StackChild, StackNode}; use crate::pretty::pretty; +use crate::eco::EcoString; use crate::syntax::*; /// Execute a template to produce a layout tree. @@ -102,18 +104,25 @@ impl ExecWithMap for HeadingNode { impl ExecWithMap for ListItem { fn exec_with_map(&self, ctx: &mut ExecContext, map: &ExprMap) { - exec_item(ctx, "•".to_string(), &self.body, map); + exec_item(ctx, '•'.into(), &self.body, map); } } impl ExecWithMap for EnumItem { fn exec_with_map(&self, ctx: &mut ExecContext, map: &ExprMap) { - let label = self.number.unwrap_or(1).to_string() + "."; + let mut label = EcoString::new(); + write!(&mut label, "{}", self.number.unwrap_or(1)).unwrap(); + label.push('.'); exec_item(ctx, label, &self.body, map); } } -fn exec_item(ctx: &mut ExecContext, label: String, body: &SyntaxTree, map: &ExprMap) { +fn exec_item( + ctx: &mut ExecContext, + label: EcoString, + body: &SyntaxTree, + map: &ExprMap, +) { let label = ctx.exec_stack(|ctx| ctx.push_text(label)); let body = ctx.exec_tree_stack(body, map); let stack = StackNode { -- cgit v1.2.3