pub struct SourceSnippet { /* private fields */ }
Expand description
A snippet of source code.
Implementations§
Source§impl SourceSnippet
impl SourceSnippet
Sourcepub fn build_from_latin1(
start_line: usize,
source: &[u8],
tab_width: usize,
) -> Self
pub fn build_from_latin1( start_line: usize, source: &[u8], tab_width: usize, ) -> Self
Creates a snippet from a Latin-1 (ISO 8859-1) source.
“\n” and “\r\n” are treated as line breaks.
Control characters (except tabs and line breaks) are represented as
<XX>
as alternative text.
Sourcepub fn build_from_latin1_ex<FnCtrl>(
start_line: usize,
source: &[u8],
on_control: FnCtrl,
) -> Self
pub fn build_from_latin1_ex<FnCtrl>( start_line: usize, source: &[u8], on_control: FnCtrl, ) -> Self
Creates a snippet from a Latin-1 (ISO 8859-1) source.
“\n” and “\r\n” are treated as line breaks.
on_control
is used to handle control characters (that are not line
breaks). on_control
also returns a boolean to indicate if the text
should be rendered as alternative.
Source§impl SourceSnippet
impl SourceSnippet
Sourcepub fn build_from_utf8(
start_line: usize,
source: &[u8],
tab_width: usize,
) -> Self
pub fn build_from_utf8( start_line: usize, source: &[u8], tab_width: usize, ) -> Self
Creates a snippet from a UTF-8 (possibly broken) source.
“\n” and “\r\n” are treated as line breaks.
Control characters (except tabs and line breaks) are represented as
<XXXX>
as alternative text. Each byte of invalid UTF-8 sequences is
represented as <XX>
as alternative text.
Sourcepub fn build_from_utf8_ex<FnCtrl, FnInv>(
start_line: usize,
source: &[u8],
on_control: FnCtrl,
on_invalid: FnInv,
invalid_multi: bool,
) -> Self
pub fn build_from_utf8_ex<FnCtrl, FnInv>( start_line: usize, source: &[u8], on_control: FnCtrl, on_invalid: FnInv, invalid_multi: bool, ) -> Self
Creates a snippet from a UTF-8 (possibly broken) source.
“\n” and “\r\n” are treated as line breaks.
on_control
is used to handle ASCII control characters (that are not
line breaks). on_invalid
and invalid_multi
are used to handle
invalid UTF-8 sequences.
When invalid_multi
is true
, on_invalid
is called for each byte
of an invalid UTF-8 sequence. Otherwise, on_invalid
is called once
with the entire sequence.
on_control
and on_invalid
also return a boolean to indicate if the
text should be rendered as alternative.
Source§impl SourceSnippet
impl SourceSnippet
pub fn get_line_col(&self, pos: usize) -> (usize, usize)
Trait Implementations§
Source§impl Clone for SourceSnippet
impl Clone for SourceSnippet
Source§fn clone(&self) -> SourceSnippet
fn clone(&self) -> SourceSnippet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more