diff --git a/.lock b/.lock new file mode 100644 index 0000000..e69de29 diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/crates.js b/crates.js new file mode 100644 index 0000000..4fb7a3a --- /dev/null +++ b/crates.js @@ -0,0 +1 @@ +window.ALL_CRATES = ["posix_space"]; \ No newline at end of file diff --git a/help.html b/help.html new file mode 100644 index 0000000..6dabe5e --- /dev/null +++ b/help.html @@ -0,0 +1 @@ +
pub fn is_space(byte: u8) -> bool
Determine whether the given byte is in space POSIX character class.
+In the POSIX locale, exactly <space>, <form-feed>, <newline>, +<carriage-return>, <tab>, and <vertical-tab> shall be included.
+This function differs from u8::is_ascii_whitespace
in that <vertical-tab>,
+\x0B
, is considered a space.
assert!(posix_space::is_space(b' '));
+assert!(posix_space::is_space(b'\x0C'));
+assert!(posix_space::is_space(b'\n'));
+assert!(posix_space::is_space(b'\r'));
+assert!(posix_space::is_space(b'\t'));
+assert!(posix_space::is_space(b'\x0B'));
Other ASCII characters are not POSIX spaces:
+ +assert!(!posix_space::is_space(b'C'));
+assert!(!posix_space::is_space(b'&'));
+assert!(!posix_space::is_space(b'\x7F'));
Non-ASCII bytes are not POSIX spaces:
+ +assert!(!posix_space::is_space(b'\x80'));
+assert!(!posix_space::is_space(b'\xFF'));
A small crate which determines if a byte is classified as a space in the +POSIX locale per POSIX.1-2017, chapter 7, Locale.
+++space
+Define characters to be classified as white-space characters.
+In the POSIX locale, exactly <space>, <form-feed>, <newline>, <carriage-return>, +<tab>, and <vertical-tab> shall be included.
+
The function defined in this crate should have equivalent behavior to the C
+function isspace
as defined in ctype.h
.
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +
#![warn(clippy::all)]
+#![warn(clippy::pedantic)]
+#![warn(clippy::cargo)]
+#![allow(unknown_lints)]
+#![warn(missing_copy_implementations)]
+#![warn(missing_debug_implementations)]
+#![warn(missing_docs)]
+#![warn(rust_2018_idioms)]
+#![warn(trivial_casts, trivial_numeric_casts)]
+#![warn(unsafe_op_in_unsafe_fn)]
+#![warn(unused_qualifications)]
+#![warn(variant_size_differences)]
+#![forbid(unsafe_code)]
+// Enable feature callouts in generated documentation:
+// https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html
+//
+// This approach is borrowed from tokio.
+#![cfg_attr(docsrs, feature(doc_cfg))]
+#![cfg_attr(docsrs, feature(doc_alias))]
+
+//! A small crate which determines if a byte is classified as a space in the
+//! POSIX locale per [POSIX.1-2017], chapter 7, [Locale].
+//!
+//! [POSIX.1-2017]: https://pubs.opengroup.org/onlinepubs/9699919799/mindex.html
+//! [Locale]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html
+//!
+//! > **space**
+//! >
+//! > Define characters to be classified as white-space characters.
+//! >
+//! > In the POSIX locale, exactly \<space\>, \<form-feed\>, \<newline\>, \<carriage-return\>,
+//! > \<tab\>, and \<vertical-tab\> shall be included.
+//!
+//! The function defined in this crate should have equivalent behavior to the C
+//! function [`isspace`] as defined in `ctype.h`.
+//!
+//! [`isspace`]: https://linux.die.net/man/3/isspace
+
+#![doc(html_root_url = "https://docs.rs/posix-space/1.0.4")]
+#![no_std]
+
+/// Determine whether the given byte is in **space** POSIX character class.
+///
+/// In the POSIX locale, exactly \<space\>, \<form-feed\>, \<newline\>,
+/// \<carriage-return\>, \<tab\>, and \<vertical-tab\> shall be included.
+///
+/// # Compatibility
+///
+/// This function differs from [`u8::is_ascii_whitespace`] in that \<vertical-tab\>,
+/// `\x0B`, is considered a **space**.
+///
+/// # Examples
+///
+/// ```
+/// assert!(posix_space::is_space(b' '));
+/// assert!(posix_space::is_space(b'\x0C'));
+/// assert!(posix_space::is_space(b'\n'));
+/// assert!(posix_space::is_space(b'\r'));
+/// assert!(posix_space::is_space(b'\t'));
+/// assert!(posix_space::is_space(b'\x0B'));
+/// ```
+///
+/// Other ASCII characters are not POSIX spaces:
+///
+/// ```
+/// assert!(!posix_space::is_space(b'C'));
+/// assert!(!posix_space::is_space(b'&'));
+/// assert!(!posix_space::is_space(b'\x7F'));
+/// ```
+///
+/// Non-ASCII bytes are not POSIX spaces:
+///
+/// ```
+/// assert!(!posix_space::is_space(b'\x80'));
+/// assert!(!posix_space::is_space(b'\xFF'));
+/// ```
+#[must_use]
+pub fn is_space(byte: u8) -> bool {
+ byte.is_ascii_whitespace() || byte == b'\x0B'
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ // ```
+ // [3.1.2] > (0..255).each { |b| puts "(0x#{b.to_s(16).upcase}, #{b.chr.match?(/[[:space:]]/)}, #{b.chr.inspect})," }
+ // ```
+ const BYTE_TO_POSIX_SPACE: [(u8, bool, &str); 256] = [
+ (0x0, false, r"\x00"),
+ (0x1, false, r"\x01"),
+ (0x2, false, r"\x02"),
+ (0x3, false, r"\x03"),
+ (0x4, false, r"\x04"),
+ (0x5, false, r"\x05"),
+ (0x6, false, r"\x06"),
+ (0x7, false, r"\a"),
+ (0x8, false, r"\b"),
+ (0x9, true, r"\t"),
+ (0xA, true, r"\n"),
+ (0xB, true, r"\v"),
+ (0xC, true, r"\f"),
+ (0xD, true, r"\r"),
+ (0xE, false, r"\x0E"),
+ (0xF, false, r"\x0F"),
+ (0x10, false, r"\x10"),
+ (0x11, false, r"\x11"),
+ (0x12, false, r"\x12"),
+ (0x13, false, r"\x13"),
+ (0x14, false, r"\x14"),
+ (0x15, false, r"\x15"),
+ (0x16, false, r"\x16"),
+ (0x17, false, r"\x17"),
+ (0x18, false, r"\x18"),
+ (0x19, false, r"\x19"),
+ (0x1A, false, r"\x1A"),
+ (0x1B, false, r"\e"),
+ (0x1C, false, r"\x1C"),
+ (0x1D, false, r"\x1D"),
+ (0x1E, false, r"\x1E"),
+ (0x1F, false, r"\x1F"),
+ (0x20, true, " "),
+ (0x21, false, "!"),
+ (0x22, false, r#"\""#),
+ (0x23, false, "#"),
+ (0x24, false, "$"),
+ (0x25, false, "%"),
+ (0x26, false, "&"),
+ (0x27, false, "'"),
+ (0x28, false, "("),
+ (0x29, false, ")"),
+ (0x2A, false, "*"),
+ (0x2B, false, "+"),
+ (0x2C, false, ","),
+ (0x2D, false, "-"),
+ (0x2E, false, "."),
+ (0x2F, false, "/"),
+ (0x30, false, "0"),
+ (0x31, false, "1"),
+ (0x32, false, "2"),
+ (0x33, false, "3"),
+ (0x34, false, "4"),
+ (0x35, false, "5"),
+ (0x36, false, "6"),
+ (0x37, false, "7"),
+ (0x38, false, "8"),
+ (0x39, false, "9"),
+ (0x3A, false, ":"),
+ (0x3B, false, ";"),
+ (0x3C, false, "<"),
+ (0x3D, false, "="),
+ (0x3E, false, ">"),
+ (0x3F, false, "?"),
+ (0x40, false, "@"),
+ (0x41, false, "A"),
+ (0x42, false, "B"),
+ (0x43, false, "C"),
+ (0x44, false, "D"),
+ (0x45, false, "E"),
+ (0x46, false, "F"),
+ (0x47, false, "G"),
+ (0x48, false, "H"),
+ (0x49, false, "I"),
+ (0x4A, false, "J"),
+ (0x4B, false, "K"),
+ (0x4C, false, "L"),
+ (0x4D, false, "M"),
+ (0x4E, false, "N"),
+ (0x4F, false, "O"),
+ (0x50, false, "P"),
+ (0x51, false, "Q"),
+ (0x52, false, "R"),
+ (0x53, false, "S"),
+ (0x54, false, "T"),
+ (0x55, false, "U"),
+ (0x56, false, "V"),
+ (0x57, false, "W"),
+ (0x58, false, "X"),
+ (0x59, false, "Y"),
+ (0x5A, false, "Z"),
+ (0x5B, false, "["),
+ (0x5C, false, r"\\"),
+ (0x5D, false, "]"),
+ (0x5E, false, "^"),
+ (0x5F, false, "_"),
+ (0x60, false, "`"),
+ (0x61, false, "a"),
+ (0x62, false, "b"),
+ (0x63, false, "c"),
+ (0x64, false, "d"),
+ (0x65, false, "e"),
+ (0x66, false, "f"),
+ (0x67, false, "g"),
+ (0x68, false, "h"),
+ (0x69, false, "i"),
+ (0x6A, false, "j"),
+ (0x6B, false, "k"),
+ (0x6C, false, "l"),
+ (0x6D, false, "m"),
+ (0x6E, false, "n"),
+ (0x6F, false, "o"),
+ (0x70, false, "p"),
+ (0x71, false, "q"),
+ (0x72, false, "r"),
+ (0x73, false, "s"),
+ (0x74, false, "t"),
+ (0x75, false, "u"),
+ (0x76, false, "v"),
+ (0x77, false, "w"),
+ (0x78, false, "x"),
+ (0x79, false, "y"),
+ (0x7A, false, "z"),
+ (0x7B, false, "{"),
+ (0x7C, false, "|"),
+ (0x7D, false, "}"),
+ (0x7E, false, "~"),
+ (0x7F, false, r"\x7F"),
+ (0x80, false, r"\x80"),
+ (0x81, false, r"\x81"),
+ (0x82, false, r"\x82"),
+ (0x83, false, r"\x83"),
+ (0x84, false, r"\x84"),
+ (0x85, false, r"\x85"),
+ (0x86, false, r"\x86"),
+ (0x87, false, r"\x87"),
+ (0x88, false, r"\x88"),
+ (0x89, false, r"\x89"),
+ (0x8A, false, r"\x8A"),
+ (0x8B, false, r"\x8B"),
+ (0x8C, false, r"\x8C"),
+ (0x8D, false, r"\x8D"),
+ (0x8E, false, r"\x8E"),
+ (0x8F, false, r"\x8F"),
+ (0x90, false, r"\x90"),
+ (0x91, false, r"\x91"),
+ (0x92, false, r"\x92"),
+ (0x93, false, r"\x93"),
+ (0x94, false, r"\x94"),
+ (0x95, false, r"\x95"),
+ (0x96, false, r"\x96"),
+ (0x97, false, r"\x97"),
+ (0x98, false, r"\x98"),
+ (0x99, false, r"\x99"),
+ (0x9A, false, r"\x9A"),
+ (0x9B, false, r"\x9B"),
+ (0x9C, false, r"\x9C"),
+ (0x9D, false, r"\x9D"),
+ (0x9E, false, r"\x9E"),
+ (0x9F, false, r"\x9F"),
+ (0xA0, false, r"\xA0"),
+ (0xA1, false, r"\xA1"),
+ (0xA2, false, r"\xA2"),
+ (0xA3, false, r"\xA3"),
+ (0xA4, false, r"\xA4"),
+ (0xA5, false, r"\xA5"),
+ (0xA6, false, r"\xA6"),
+ (0xA7, false, r"\xA7"),
+ (0xA8, false, r"\xA8"),
+ (0xA9, false, r"\xA9"),
+ (0xAA, false, r"\xAA"),
+ (0xAB, false, r"\xAB"),
+ (0xAC, false, r"\xAC"),
+ (0xAD, false, r"\xAD"),
+ (0xAE, false, r"\xAE"),
+ (0xAF, false, r"\xAF"),
+ (0xB0, false, r"\xB0"),
+ (0xB1, false, r"\xB1"),
+ (0xB2, false, r"\xB2"),
+ (0xB3, false, r"\xB3"),
+ (0xB4, false, r"\xB4"),
+ (0xB5, false, r"\xB5"),
+ (0xB6, false, r"\xB6"),
+ (0xB7, false, r"\xB7"),
+ (0xB8, false, r"\xB8"),
+ (0xB9, false, r"\xB9"),
+ (0xBA, false, r"\xBA"),
+ (0xBB, false, r"\xBB"),
+ (0xBC, false, r"\xBC"),
+ (0xBD, false, r"\xBD"),
+ (0xBE, false, r"\xBE"),
+ (0xBF, false, r"\xBF"),
+ (0xC0, false, r"\xC0"),
+ (0xC1, false, r"\xC1"),
+ (0xC2, false, r"\xC2"),
+ (0xC3, false, r"\xC3"),
+ (0xC4, false, r"\xC4"),
+ (0xC5, false, r"\xC5"),
+ (0xC6, false, r"\xC6"),
+ (0xC7, false, r"\xC7"),
+ (0xC8, false, r"\xC8"),
+ (0xC9, false, r"\xC9"),
+ (0xCA, false, r"\xCA"),
+ (0xCB, false, r"\xCB"),
+ (0xCC, false, r"\xCC"),
+ (0xCD, false, r"\xCD"),
+ (0xCE, false, r"\xCE"),
+ (0xCF, false, r"\xCF"),
+ (0xD0, false, r"\xD0"),
+ (0xD1, false, r"\xD1"),
+ (0xD2, false, r"\xD2"),
+ (0xD3, false, r"\xD3"),
+ (0xD4, false, r"\xD4"),
+ (0xD5, false, r"\xD5"),
+ (0xD6, false, r"\xD6"),
+ (0xD7, false, r"\xD7"),
+ (0xD8, false, r"\xD8"),
+ (0xD9, false, r"\xD9"),
+ (0xDA, false, r"\xDA"),
+ (0xDB, false, r"\xDB"),
+ (0xDC, false, r"\xDC"),
+ (0xDD, false, r"\xDD"),
+ (0xDE, false, r"\xDE"),
+ (0xDF, false, r"\xDF"),
+ (0xE0, false, r"\xE0"),
+ (0xE1, false, r"\xE1"),
+ (0xE2, false, r"\xE2"),
+ (0xE3, false, r"\xE3"),
+ (0xE4, false, r"\xE4"),
+ (0xE5, false, r"\xE5"),
+ (0xE6, false, r"\xE6"),
+ (0xE7, false, r"\xE7"),
+ (0xE8, false, r"\xE8"),
+ (0xE9, false, r"\xE9"),
+ (0xEA, false, r"\xEA"),
+ (0xEB, false, r"\xEB"),
+ (0xEC, false, r"\xEC"),
+ (0xED, false, r"\xED"),
+ (0xEE, false, r"\xEE"),
+ (0xEF, false, r"\xEF"),
+ (0xF0, false, r"\xF0"),
+ (0xF1, false, r"\xF1"),
+ (0xF2, false, r"\xF2"),
+ (0xF3, false, r"\xF3"),
+ (0xF4, false, r"\xF4"),
+ (0xF5, false, r"\xF5"),
+ (0xF6, false, r"\xF6"),
+ (0xF7, false, r"\xF7"),
+ (0xF8, false, r"\xF8"),
+ (0xF9, false, r"\xF9"),
+ (0xFA, false, r"\xFA"),
+ (0xFB, false, r"\xFB"),
+ (0xFC, false, r"\xFC"),
+ (0xFD, false, r"\xFD"),
+ (0xFE, false, r"\xFE"),
+ (0xFF, false, r"\xFF"),
+ ];
+
+ #[test]
+ fn space_character_class() {
+ let test_cases = BYTE_TO_POSIX_SPACE;
+ for &(byte, is_posix_space, display) in test_cases.iter() {
+ assert_eq!(is_space(byte), is_posix_space, "{} - {}", byte, display);
+ }
+ }
+
+ #[test]
+ fn non_ascii_bytes_are_not_posix_spaces() {
+ for byte in 0..=core::u8::MAX {
+ if byte.is_ascii() {
+ continue;
+ }
+ assert!(!is_space(byte), "for byte {}", byte);
+ }
+ }
+}
+
+// Ensure code blocks in `README.md` compile.
+//
+// This module and macro declaration should be kept at the end of the file, in
+// order to not interfere with code coverage.
+#[cfg(doctest)]
+macro_rules! readme {
+ ($x:expr) => {
+ #[doc = $x]
+ mod readme {}
+ };
+ () => {
+ readme!(include_str!("../README.md"));
+ };
+}
+#[cfg(doctest)]
+readme!();
+
fn:
) to \
+ restrict the search to a given item kind.","Accepted kinds are: fn
, mod
, struct
, \
+ enum
, trait
, type
, macro
, \
+ and const
.","Search functions by type signature (e.g., vec -> usize
or \
+ -> vec
or String, enum:Cow -> bool
)","You can look for items with an exact name by putting double quotes around \
+ your request: \"string\"
","Look for functions that accept or return \
+ slices and \
+ arrays by writing \
+ square brackets (e.g., -> [u8]
or [] -> Option
)","Look for items inside another one by searching for a path: vec::Vec
",].map(x=>""+x+"
").join("");const div_infos=document.createElement("div");addClass(div_infos,"infos");div_infos.innerHTML="${value.replaceAll(" ", " ")}
`}else{error[index]=value}});output+=`