usecrate::bundle::FluentBundle; usecrate::memoizer::MemoizerKind; usecrate::resolver::{ResolveValue, ResolverError, WriteValue}; usecrate::types::FluentValue; usecrate::{FluentArgs, FluentError, FluentResource}; use fluent_syntax::ast; use std::borrow::Borrow; use std::fmt;
/// State for a single `ResolveValue::to_value` call. pubstruct Scope<'scope, 'errors, R, M> { /// The current `FluentBundle` instance. pub bundle: &'scope FluentBundle<R, M>, /// The current arguments passed by the developer. pub(super) args: Option<&'scope FluentArgs<'scope>>, /// Local args pub(super) local_args: Option<FluentArgs<'scope>>, /// The running count of resolved placeables. Used to detect the Billion /// Laughs and Quadratic Blowup attacks. pub(super) placeables: u8, /// Tracks hashes to prevent infinite recursion.
travelled: smallvec::SmallVec<[&'scope ast::Pattern<&'scope str>; 2]>, /// Track errors accumulated during resolving. pub errors: Option<&'errors mut Vec<FluentError>>, /// Makes the resolver bail. pub dirty: bool,
}
// This method allows us to lazily add Pattern on the stack, // only if the Pattern::resolve has been called on an empty stack. // // This is the case when pattern is called from Bundle and it // allows us to fast-path simple resolutions, and only use the stack // for placeables. pubfn maybe_track<W>(
&mutself,
w: &mut W,
pattern: &'scope ast::Pattern<&str>,
exp: &'scope ast::Expression<&str>,
) -> fmt::Result where
R: Borrow<FluentResource>,
W: fmt::Write,
M: MemoizerKind,
{ ifself.travelled.is_empty() { self.travelled.push(pattern);
}
exp.write(w, self)?; ifself.dirty {
w.write_char('{')?;
exp.write_error(w)?;
w.write_char('}')
} else {
Ok(())
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.