diff options
Diffstat (limited to 'vendor/bstr/examples')
-rw-r--r-- | vendor/bstr/examples/graphemes-std.rs | 25 | ||||
-rw-r--r-- | vendor/bstr/examples/graphemes.rs | 22 | ||||
-rw-r--r-- | vendor/bstr/examples/lines-std.rs | 17 | ||||
-rw-r--r-- | vendor/bstr/examples/lines.rs | 17 | ||||
-rw-r--r-- | vendor/bstr/examples/uppercase-std.rs | 15 | ||||
-rw-r--r-- | vendor/bstr/examples/uppercase.rs | 18 | ||||
-rw-r--r-- | vendor/bstr/examples/words-std.rs | 18 | ||||
-rw-r--r-- | vendor/bstr/examples/words.rs | 15 |
8 files changed, 147 insertions, 0 deletions
diff --git a/vendor/bstr/examples/graphemes-std.rs b/vendor/bstr/examples/graphemes-std.rs new file mode 100644 index 0000000..647739d --- /dev/null +++ b/vendor/bstr/examples/graphemes-std.rs @@ -0,0 +1,25 @@ +use std::error::Error; +use std::io::{self, BufRead, Write}; + +use unicode_segmentation::UnicodeSegmentation; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut stdin = stdin.lock(); + let mut stdout = io::BufWriter::new(io::stdout()); + + let mut line = String::new(); + while stdin.read_line(&mut line)? > 0 { + let end = line + .grapheme_indices(true) + .map(|(start, g)| start + g.len()) + .take(10) + .last() + .unwrap_or(line.len()); + stdout.write_all(line[..end].trim_end().as_bytes())?; + stdout.write_all(b"\n")?; + + line.clear(); + } + Ok(()) +} diff --git a/vendor/bstr/examples/graphemes.rs b/vendor/bstr/examples/graphemes.rs new file mode 100644 index 0000000..6adc701 --- /dev/null +++ b/vendor/bstr/examples/graphemes.rs @@ -0,0 +1,22 @@ +use std::error::Error; +use std::io::{self, Write}; + +use bstr::{io::BufReadExt, ByteSlice}; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut stdout = io::BufWriter::new(io::stdout()); + + stdin.lock().for_byte_line_with_terminator(|line| { + let end = line + .grapheme_indices() + .map(|(_, end, _)| end) + .take(10) + .last() + .unwrap_or(line.len()); + stdout.write_all(line[..end].trim_end())?; + stdout.write_all(b"\n")?; + Ok(true) + })?; + Ok(()) +} diff --git a/vendor/bstr/examples/lines-std.rs b/vendor/bstr/examples/lines-std.rs new file mode 100644 index 0000000..69fc6a5 --- /dev/null +++ b/vendor/bstr/examples/lines-std.rs @@ -0,0 +1,17 @@ +use std::error::Error; +use std::io::{self, BufRead, Write}; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut stdin = stdin.lock(); + let mut stdout = io::BufWriter::new(io::stdout()); + + let mut line = String::new(); + while stdin.read_line(&mut line)? > 0 { + if line.contains("Dimension") { + stdout.write_all(line.as_bytes())?; + } + line.clear(); + } + Ok(()) +} diff --git a/vendor/bstr/examples/lines.rs b/vendor/bstr/examples/lines.rs new file mode 100644 index 0000000..c392a22 --- /dev/null +++ b/vendor/bstr/examples/lines.rs @@ -0,0 +1,17 @@ +use std::error::Error; +use std::io::{self, Write}; + +use bstr::{io::BufReadExt, ByteSlice}; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut stdout = io::BufWriter::new(io::stdout()); + + stdin.lock().for_byte_line_with_terminator(|line| { + if line.contains_str("Dimension") { + stdout.write_all(line)?; + } + Ok(true) + })?; + Ok(()) +} diff --git a/vendor/bstr/examples/uppercase-std.rs b/vendor/bstr/examples/uppercase-std.rs new file mode 100644 index 0000000..672bd71 --- /dev/null +++ b/vendor/bstr/examples/uppercase-std.rs @@ -0,0 +1,15 @@ +use std::error::Error; +use std::io::{self, BufRead, Write}; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut stdin = stdin.lock(); + let mut stdout = io::BufWriter::new(io::stdout()); + + let mut line = String::new(); + while stdin.read_line(&mut line)? > 0 { + stdout.write_all(line.to_uppercase().as_bytes())?; + line.clear(); + } + Ok(()) +} diff --git a/vendor/bstr/examples/uppercase.rs b/vendor/bstr/examples/uppercase.rs new file mode 100644 index 0000000..1eb798a --- /dev/null +++ b/vendor/bstr/examples/uppercase.rs @@ -0,0 +1,18 @@ +use std::error::Error; +use std::io::{self, Write}; + +use bstr::{io::BufReadExt, ByteSlice}; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut stdout = io::BufWriter::new(io::stdout()); + + let mut upper = vec![]; + stdin.lock().for_byte_line_with_terminator(|line| { + upper.clear(); + line.to_uppercase_into(&mut upper); + stdout.write_all(&upper)?; + Ok(true) + })?; + Ok(()) +} diff --git a/vendor/bstr/examples/words-std.rs b/vendor/bstr/examples/words-std.rs new file mode 100644 index 0000000..aeeeb26 --- /dev/null +++ b/vendor/bstr/examples/words-std.rs @@ -0,0 +1,18 @@ +use std::error::Error; +use std::io::{self, BufRead}; + +use unicode_segmentation::UnicodeSegmentation; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut stdin = stdin.lock(); + + let mut words = 0; + let mut line = String::new(); + while stdin.read_line(&mut line)? > 0 { + words += line.unicode_words().count(); + line.clear(); + } + println!("{}", words); + Ok(()) +} diff --git a/vendor/bstr/examples/words.rs b/vendor/bstr/examples/words.rs new file mode 100644 index 0000000..db305da --- /dev/null +++ b/vendor/bstr/examples/words.rs @@ -0,0 +1,15 @@ +use std::error::Error; +use std::io; + +use bstr::{io::BufReadExt, ByteSlice}; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut words = 0; + stdin.lock().for_byte_line_with_terminator(|line| { + words += line.words().count(); + Ok(true) + })?; + println!("{}", words); + Ok(()) +} |