-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic streaming validation
Located in `simdutf8::basic::imp` with the public_imp feature flag
- Loading branch information
Showing
9 changed files
with
480 additions
and
41 deletions.
There are no files selected for viewing
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,36 @@ | ||
#[cfg(feature = "public_imp")] | ||
use simdutf8::basic::imp::Utf8Validator; | ||
|
||
#[allow(unused_imports)] | ||
use std::io::{stdin, Read, Result}; | ||
|
||
#[cfg(feature = "public_imp")] | ||
fn main() -> Result<()> { | ||
unsafe { | ||
if !std::is_x86_feature_detected!("avx2") { | ||
panic!("This example only works with CPUs supporting AVX 2"); | ||
} | ||
|
||
let mut validator = simdutf8::basic::imp::x86::avx2::Utf8ValidatorImp::new(); | ||
let mut buf = vec![0; 8192]; | ||
loop { | ||
let bytes_read = stdin().read(buf.as_mut())?; | ||
if bytes_read == 0 { | ||
break; | ||
} | ||
validator.update(&buf); | ||
} | ||
|
||
if validator.finalize().is_ok() { | ||
println!("Input is valid UTF-8"); | ||
} else { | ||
println!("Input is not valid UTF-8"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Dummy main. This example requires the crate feature `public_imp`. | ||
#[cfg(not(feature = "public_imp"))] | ||
fn main() {} |
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
Oops, something went wrong.