Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,37 @@
|
||||
//! Input decoding is a job profile, independent of e-TeX primitive availability.
|
||||
//! Both paths retain original byte offsets; the byte path never recodes a file.
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize,
|
||||
)]
|
||||
pub enum InputProfile {
|
||||
TeX8Bit,
|
||||
#[default]
|
||||
UnicodeScalar,
|
||||
}
|
||||
impl InputProfile {
|
||||
pub(super) fn characters(self, data: &[u8]) -> Result<Characters<'_>, std::str::Utf8Error> {
|
||||
Ok(match self {
|
||||
Self::TeX8Bit => Characters::Bytes(data.iter().enumerate()),
|
||||
Self::UnicodeScalar => Characters::Unicode(std::str::from_utf8(data)?.char_indices()),
|
||||
})
|
||||
}
|
||||
pub(super) fn width(self, c: char) -> usize {
|
||||
match self {
|
||||
Self::TeX8Bit => 1,
|
||||
Self::UnicodeScalar => c.len_utf8(),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(super) enum Characters<'a> {
|
||||
Bytes(std::iter::Enumerate<std::slice::Iter<'a, u8>>),
|
||||
Unicode(std::str::CharIndices<'a>),
|
||||
}
|
||||
impl Iterator for Characters<'_> {
|
||||
type Item = (usize, char);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self {
|
||||
Self::Bytes(iter) => iter.next().map(|(i, &b)| (i, char::from(b))),
|
||||
Self::Unicode(iter) => iter.next(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user