-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad0b4ac
commit bb1ac9b
Showing
54 changed files
with
4,069 additions
and
437 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//! Parsing common data elements and their members from documentation. | ||
|
||
use std::iter::Peekable; | ||
use std::str::Lines; | ||
|
||
/// Conventional line endings in text files (platform-specific). | ||
#[cfg(windows)] | ||
pub const LINE_ENDING: &str = "\r\n"; | ||
|
||
/// Conventional line endings in text files (platform-specific). | ||
#[cfg(not(windows))] | ||
pub const LINE_ENDING: &str = "\n"; | ||
|
||
pub mod cde; | ||
|
||
/// Reads from an iterator over lines and trims the concatenates lines together. | ||
/// This is useful when you want to treat a multiline comment as a single | ||
/// [`String`]. | ||
/// | ||
/// Note that, if the contiguous lines are postceded by an empty line, then the | ||
/// postceding empty line is also consumed. This is convenient for calling this | ||
/// function multiple times in a row on the same iterator. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use ccdi_cde as cde; | ||
/// | ||
/// use cde::parse::trim_and_concat_contiguous_lines; | ||
/// | ||
/// let mut lines = "hello\nthere,\nworld\n\nfoo\nbar\n\n\"baz\ntest\"".lines().peekable(); | ||
/// | ||
/// assert_eq!( | ||
/// trim_and_concat_contiguous_lines(&mut lines), | ||
/// Some(String::from("hello there, world")) | ||
/// ); | ||
/// | ||
/// assert_eq!( | ||
/// trim_and_concat_contiguous_lines(&mut lines), | ||
/// Some(String::from("foo bar")) | ||
/// ); | ||
/// | ||
/// assert_eq!( | ||
/// trim_and_concat_contiguous_lines(&mut lines), | ||
/// Some(String::from(r#""baz test""#)) | ||
/// ); | ||
/// | ||
/// assert_eq!( | ||
/// trim_and_concat_contiguous_lines(&mut lines), | ||
/// None | ||
/// ); | ||
/// ``` | ||
pub fn trim_and_concat_contiguous_lines(lines: &mut Peekable<Lines<'_>>) -> Option<String> { | ||
// If the first line is `None`, return `None`; | ||
lines.peek()?; | ||
|
||
let mut results = vec![]; | ||
|
||
for line in lines.by_ref() { | ||
let line = line.trim(); | ||
|
||
// Consume the postceding empty line. | ||
if line.is_empty() { | ||
break; | ||
} | ||
|
||
results.push(line); | ||
} | ||
|
||
Some(results.join(" ").trim().to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Parsing information for common data elements. | ||
|
||
pub mod entity; | ||
pub mod member; | ||
|
||
pub use entity::Entity; | ||
pub use member::Member; |
Oops, something went wrong.