Compare commits
No commits in common. "e42edb3f49ff0458e88ad79fdc8a26bf52915cfc" and "d9a3b1378075142e0dc0901a11570dde67310889" have entirely different histories.
e42edb3f49
...
d9a3b13780
@ -1 +1 @@
|
|||||||
<code>{.value}</code>
|
!!!!!!!! inline_source_block
|
||||||
|
@ -1,9 +1 @@
|
|||||||
<table>
|
!!!!!!!! src_block
|
||||||
<tbody>
|
|
||||||
{#.lines}
|
|
||||||
<tr>
|
|
||||||
<td><code>{.}</code></td>
|
|
||||||
</tr>
|
|
||||||
{/.lines}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
@ -9,19 +9,15 @@ use crate::intermediate::IInlineSourceBlock;
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
#[serde(rename = "inline_source_block")]
|
#[serde(rename = "inline_source_block")]
|
||||||
pub(crate) struct RenderInlineSourceBlock {
|
pub(crate) struct RenderInlineSourceBlock {}
|
||||||
value: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RenderInlineSourceBlock {
|
impl RenderInlineSourceBlock {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
output_directory: &Path,
|
output_directory: &Path,
|
||||||
output_file: &Path,
|
output_file: &Path,
|
||||||
original: &IInlineSourceBlock,
|
comment: &IInlineSourceBlock,
|
||||||
) -> Result<RenderInlineSourceBlock, CustomError> {
|
) -> Result<RenderInlineSourceBlock, CustomError> {
|
||||||
Ok(RenderInlineSourceBlock {
|
Ok(RenderInlineSourceBlock {})
|
||||||
value: original.value.clone(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,7 @@ use crate::intermediate::ISrcBlock;
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
#[serde(rename = "src_block")]
|
#[serde(rename = "src_block")]
|
||||||
pub(crate) struct RenderSrcBlock {
|
pub(crate) struct RenderSrcBlock {}
|
||||||
lines: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RenderSrcBlock {
|
impl RenderSrcBlock {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
@ -20,8 +18,6 @@ impl RenderSrcBlock {
|
|||||||
output_file: &Path,
|
output_file: &Path,
|
||||||
original: &ISrcBlock,
|
original: &ISrcBlock,
|
||||||
) -> Result<RenderSrcBlock, CustomError> {
|
) -> Result<RenderSrcBlock, CustomError> {
|
||||||
Ok(RenderSrcBlock {
|
Ok(RenderSrcBlock {})
|
||||||
lines: original.lines.clone(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,13 @@ use crate::error::CustomError;
|
|||||||
use super::registry::Registry;
|
use super::registry::Registry;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct IInlineSourceBlock {
|
pub(crate) struct IInlineSourceBlock {}
|
||||||
pub(crate) value: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IInlineSourceBlock {
|
impl IInlineSourceBlock {
|
||||||
pub(crate) async fn new<'parse>(
|
pub(crate) async fn new<'parse>(
|
||||||
registry: &mut Registry<'parse>,
|
registry: &mut Registry<'parse>,
|
||||||
original: &organic::types::InlineSourceBlock<'parse>,
|
original: &organic::types::InlineSourceBlock<'parse>,
|
||||||
) -> Result<IInlineSourceBlock, CustomError> {
|
) -> Result<IInlineSourceBlock, CustomError> {
|
||||||
Ok(IInlineSourceBlock {
|
Ok(IInlineSourceBlock {})
|
||||||
value: original.value.to_owned(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
use super::registry::Registry;
|
use super::registry::Registry;
|
||||||
use super::util::GetFullLines;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ISrcBlock {
|
pub(crate) struct ISrcBlock {}
|
||||||
pub(crate) lines: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ISrcBlock {
|
impl ISrcBlock {
|
||||||
pub(crate) async fn new<'parse>(
|
pub(crate) async fn new<'parse>(
|
||||||
registry: &mut Registry<'parse>,
|
registry: &mut Registry<'parse>,
|
||||||
original: &organic::types::SrcBlock<'parse>,
|
original: &organic::types::SrcBlock<'parse>,
|
||||||
) -> Result<ISrcBlock, CustomError> {
|
) -> Result<ISrcBlock, CustomError> {
|
||||||
let lines = original
|
Ok(ISrcBlock {})
|
||||||
.contents
|
|
||||||
.full_lines()
|
|
||||||
.map(|s| s.to_owned())
|
|
||||||
.collect();
|
|
||||||
Ok(ISrcBlock { lines })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,129 +46,3 @@ enum CoalesceWhitespace {
|
|||||||
Normal,
|
Normal,
|
||||||
HasWhitespace { in_whitespace: bool, ret: String },
|
HasWhitespace { in_whitespace: bool, ret: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct FullLinesIterator<'i> {
|
|
||||||
inner: Option<&'i str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'i> Iterator for FullLinesIterator<'i> {
|
|
||||||
type Item = &'i str;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
if let Some(inner) = self.inner {
|
|
||||||
for (i, c) in inner.char_indices() {
|
|
||||||
if c == '\n' {
|
|
||||||
let (current_line, remainder) = inner.split_at(i + 1);
|
|
||||||
self.inner = Some(remainder);
|
|
||||||
return Some(current_line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if inner.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
let final_unterminated_line = Some(inner);
|
|
||||||
self.inner = None;
|
|
||||||
final_unterminated_line
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
if let Some(inner) = self.inner {
|
|
||||||
let line_count = {
|
|
||||||
inner.bytes().filter(|b| *b == b'\n').count()
|
|
||||||
+ (if inner.ends_with('\n') { 0 } else { 1 })
|
|
||||||
};
|
|
||||||
(line_count, Some(line_count))
|
|
||||||
} else {
|
|
||||||
(0, Some(0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExactSizeIterator for FullLinesIterator<'_> {}
|
|
||||||
|
|
||||||
pub(crate) trait GetFullLines {
|
|
||||||
fn full_lines(&self) -> FullLinesIterator<'_>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'s, S: AsRef<str>> GetFullLines for S {
|
|
||||||
fn full_lines(&self) -> FullLinesIterator<'_> {
|
|
||||||
let inner = self.as_ref();
|
|
||||||
FullLinesIterator {
|
|
||||||
inner: if inner.is_empty() { None } else { Some(inner) },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_full_lines_iterator() {
|
|
||||||
{
|
|
||||||
let input = "foo\nbar\nbaz";
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().count());
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().len());
|
|
||||||
assert_eq!(input.lines().collect::<Vec<_>>(), vec!["foo", "bar", "baz"]);
|
|
||||||
assert_eq!(
|
|
||||||
input.full_lines().collect::<Vec<_>>(),
|
|
||||||
vec!["foo\n", "bar\n", "baz"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// Trailing newline
|
|
||||||
let input = "foo\nbar\nbaz\n";
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().count());
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().len());
|
|
||||||
assert_eq!(input.lines().collect::<Vec<_>>(), vec!["foo", "bar", "baz"]);
|
|
||||||
assert_eq!(
|
|
||||||
input.full_lines().collect::<Vec<_>>(),
|
|
||||||
vec!["foo\n", "bar\n", "baz\n"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// Leading newline
|
|
||||||
let input = "\nfoo\nbar\nbaz";
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().count());
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().len());
|
|
||||||
assert_eq!(
|
|
||||||
input.lines().collect::<Vec<_>>(),
|
|
||||||
vec!["", "foo", "bar", "baz"]
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
input.full_lines().collect::<Vec<_>>(),
|
|
||||||
vec!["\n", "foo\n", "bar\n", "baz"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// Double newline
|
|
||||||
let input = "foo\nbar\n\nbaz";
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().count());
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().len());
|
|
||||||
assert_eq!(
|
|
||||||
input.lines().collect::<Vec<_>>(),
|
|
||||||
vec!["foo", "bar", "", "baz"]
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
input.full_lines().collect::<Vec<_>>(),
|
|
||||||
vec!["foo\n", "bar\n", "\n", "baz"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
let input = "";
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().count());
|
|
||||||
assert_eq!(input.lines().count(), input.full_lines().len());
|
|
||||||
assert_eq!(input.lines().collect::<Vec<_>>(), Vec::<&str>::new());
|
|
||||||
assert_eq!(input.full_lines().collect::<Vec<_>>(), Vec::<&str>::new());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user