### Resourceprep: Basic String Preparation Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Prepares a string for use as a resource name according to Resourceprep rules. This example demonstrates a successful preparation. ```rust assert_eq!("foo@bar", resourceprep("foo@bar").unwrap()); ``` -------------------------------- ### X520prep: Basic String Preparation with Case Folding Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Prepares a string using X520prep rules with case folding enabled. This is useful for case-insensitive comparisons. ```rust assert_eq!(x520prep("foo@bar", true).unwrap(), "foo@bar"); ``` -------------------------------- ### X520prep: String Preparation with Complex Characters Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Demonstrates X520prep string preparation with various characters, including those requiring mapping and normalization, with case folding disabled. ```rust assert_eq!( x520prep("J.\u{FE00} \u{9}W. \u{B}wuz h\u{0115}re", false).unwrap(), "J. W. wuz here" ); ``` -------------------------------- ### resourceprep Source: https://docs.rs/stringprep/0.1.5/stringprep/fn.resourceprep.html Prepares a string with the Resourceprep profile of the stringprep algorithm. ```APIDOC ## resourceprep ### Description Prepares a string with the Resourceprep profile of the stringprep algorithm. Nameprep is defined in RFC 3920, Appendix B. ### Signature ```rust pub fn resourceprep(s: &str) -> Result, Error> ``` ### Parameters #### Path Parameters - **s** (string) - The input string to prepare. ### Returns - **Result, Error>** - A `Cow<'_, str>` containing the prepared string on success, or an `Error` on failure. ``` -------------------------------- ### Nameprep String Preparation Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Prepares a string using the Nameprep profile. Includes a fast path for strings containing only ASCII lowercase letters, digits, periods, and hyphens. ```rust /// Prepares a string with the Nameprep profile of the stringprep algorithm. /// /// Nameprep is defined in [RFC 3491][]. /// /// [RFC 3491]: https://tools.ietf.org/html/rfc3491 pub fn nameprep(s: &str) -> Result, Error> { // fast path for ascii text if s.chars() .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '.' || c == '-') { ``` -------------------------------- ### nameprep Source: https://docs.rs/stringprep/0.1.5/stringprep/fn.nameprep.html Prepares a string with the Nameprep profile of the stringprep algorithm. ```APIDOC ## nameprep ### Description Prepares a string with the Nameprep profile of the stringprep algorithm. Nameprep is defined in RFC 3491. ### Signature ```rust pub fn nameprep(s: &str) -> Result, Error> ``` ### Parameters * `s` (*str*) - The input string to prepare. ### Returns * `Result, Error>` - A `Result` containing the prepared string as a `Cow<'_, str>` on success, or an `Error` on failure. ``` -------------------------------- ### x520prep Source: https://docs.rs/stringprep/0.1.5/stringprep/index.html Prepares a string according to the procedures described in Section 7 of ITU-T Recommendation X.520 (2019). ```APIDOC ## Function: x520prep ### Description Prepares a string according to the procedures described in Section 7 of ITU-T Recommendation X.520 (2019). ### Signature ```rust fn x520prep(s: &str) -> Result ``` ### Parameters * `s` (*&str*) - The input string to prepare. ### Returns * `Result` - A `Result` containing the prepared string or an `Error` if the operation fails. ``` -------------------------------- ### x520prep Source: https://docs.rs/stringprep/0.1.5/index.html Prepares a string according to the procedures described in Section 7 of ITU-T Recommendation X.520 (2019). ```APIDOC ## x520prep ### Description Prepares a string according to the procedures described in Section 7 of ITU-T Recommendation X.520 (2019). ### Function Signature ```rust fn x520prep(input: &str) -> Result ``` ### Parameters * `input` (*str*) - The string to prepare. ### Returns A `Result` containing the prepared string or an `Error` if the preparation fails. ``` -------------------------------- ### nodeprep Source: https://docs.rs/stringprep/0.1.5/stringprep/fn.nodeprep.html Prepares a string with the Nodeprep profile of the stringprep algorithm. ```APIDOC ## Function nodeprep ### Description Prepares a string with the Nodeprep profile of the stringprep algorithm. Nameprep is defined in RFC 3920, Appendix A. ### Signature ```rust pub fn nodeprep(s: &str) -> Result, Error> ``` ### Parameters * `s` (*str*) - The input string to prepare. ### Returns * `Result, Error>` - A `Result` containing the prepared string as a `Cow<'_, str>` on success, or an `Error` on failure. ``` -------------------------------- ### Resourceprep Profile Implementation Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Implements the Resourceprep profile of the stringprep algorithm. It handles mapping, normalization, and checks for prohibited characters. Use this for preparing strings for JID resources in XMPP. ```rust pub fn resourceprep(s: &str) -> Result, Error> { // fast path for ascii text if s.chars().all(|c| matches!(c, ' '..='~')) { return Ok(Cow::Borrowed(s)); } // B.3. Mapping let mapped = s .chars() .filter(|&c| !tables::commonly_mapped_to_nothing(c)) .collect::(); // B.4. Normalization let normalized = mapped.nfkc().collect::(); // B.5. Prohibited Output let prohibited = normalized.chars().find(|&c| { tables::non_ascii_space_character(c) /* C.1.2 */ || tables::ascii_control_character(c) /* C.2.1 */ || tables::non_ascii_control_character(c) /* C.2.2 */ || ``` -------------------------------- ### x520prep Source: https://docs.rs/stringprep/0.1.5/stringprep/fn.x520prep.html Prepares a string according to Section 7 of ITU-T Recommendation X.520 (2019). Note that this function does not remove leading, trailing, or inner spaces as described in Section 7.6. ```APIDOC ## Function x520prep ### Description Prepares a string according to the procedures described in Section 7 of ITU-T Recommendation X.520 (2019). Note that this function does _not_ remove leading, trailing, or inner spaces as described in Section 7.6, because the characters needing removal will vary across the matching rules and ASN.1 syntaxes used. ### Signature ```rust pub fn x520prep(s: &str, case_fold: bool) -> Result, Error> ``` ### Parameters * `s` (`&str`): The input string to prepare. * `case_fold` (`bool`): A boolean indicating whether to perform case folding. ### Returns * `Result, Error>`: A `Cow<'_, str>` containing the prepared string on success, or an `Error` on failure. ``` -------------------------------- ### x520prep Function Usage Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Demonstrates the usage of the x520prep function for string preparation, including handling of Unicode characters and case conversion. Ensure correct Unicode normalization and case folding are applied. ```rust assert_eq!( x520prep("J. W. wuz h\u{0115}re", true).unwrap(), "j. w. wuz h\u{0115}re" ); assert_eq!(x520prep("J.\u{FE00} \u{9}W. \u{B}wuz h\u{0115}re", true).unwrap(), "j. w. wuz h\u{0115}re"); assert_eq!(x520prep("UPPERCASED", true).unwrap(), "uppercased"); assert_starts_with_combining_char(x520prep("\u{0306}hello", true)); ``` -------------------------------- ### take Source: https://docs.rs/stringprep/0.1.5/stringprep/tables/struct.CaseFoldForNfkc.html Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ```APIDOC ## fn take(self, n: usize) -> Take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Method `take` ### Parameters - **n** (usize) - The maximum number of elements to yield. ``` -------------------------------- ### by_ref Source: https://docs.rs/stringprep/0.1.5/stringprep/tables/struct.CaseFoldForNfkc.html Creates a reference adapter for an iterator. ```APIDOC ## fn by_ref(&mut self) -> &mut Self ### Description Creates a “by reference” adapter for this instance of `Iterator`. ### Method `by_ref` ``` -------------------------------- ### x520prep Source: https://docs.rs/stringprep/0.1.5/stringprep/all.html Performs the X520prep profile for X.520 preparation. ```APIDOC ## x520prep ### Description Performs the X520prep profile for X.520 preparation. ### Function Signature `fn x520prep(input: &str) -> Result` ``` -------------------------------- ### Nameprep Profile Implementation Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Implements the Nameprep profile of the stringprep algorithm. It handles mapping, normalization, and checks for prohibited characters and bidirectional text. Use this for preparing strings for use in protocols like XMPP. ```rust pub fn nameprep(s: &str) -> Result, Error> { // fast path for common ascii text if s.chars().all(|c| matches!(c, '['..='~'])) { return Ok(Cow::Borrowed(s)); } // 3. Mapping let mapped = s .chars() .filter(|&c| !tables::commonly_mapped_to_nothing(c)) .flat_map(tables::case_fold_for_nfkc); // 4. Normalization let normalized = mapped.nfkc().collect::(); // 5. Prohibited Output let prohibited = normalized.chars().find(|&c| { tables::non_ascii_space_character(c) /* C.1.2 */ || tables::non_ascii_control_character(c) /* C.2.2 */ || tables::private_use(c) /* C.3 */ || tables::non_character_code_point(c) /* C.4 */ || tables::surrogate_code(c) /* C.5 */ || tables::inappropriate_for_plain_text(c) /* C.6 */ || tables::inappropriate_for_canonical_representation(c) /* C.7 */ || tables::change_display_properties_or_deprecated(c) /* C.9 */ || tables::tagging_character(c) /* C.9 */ }); if let Some(c) = prohibited { return Err(Error(ErrorCause::ProhibitedCharacter(c))); } // 6. Bidirectional Characters if is_prohibited_bidirectional_text(&normalized) { return Err(Error(ErrorCause::ProhibitedBidirectionalText)); } // 7 Unassigned Code Points let unassigned = normalized .chars() .find(|&c| tables::unassigned_code_point(c)); if let Some(c) = unassigned { return Err(Error(ErrorCause::ProhibitedCharacter(c))); } Ok(Cow::Owned(normalized)) } ``` -------------------------------- ### Nodeprep Profile Implementation Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Implements the Nodeprep profile for JID node names. It includes mapping, normalization, and checks for prohibited characters, including specific node characters. Use this for preparing strings for JID nodes in XMPP. ```rust pub fn nodeprep(s: &str) -> Result, Error> { // fast path for common ascii text if s.chars() .all(|c| matches!(c, '['..='~' | '0'..='9' | '('..='.' | '#'..='%')) { return Ok(Cow::Borrowed(s)); } // A.3. Mapping let mapped = s .chars() .filter(|&c| !tables::commonly_mapped_to_nothing(c)) .flat_map(tables::case_fold_for_nfkc); // A.4. Normalization let normalized = mapped.nfkc().collect::(); // A.5. Prohibited Output let prohibited = normalized.chars().find(|&c| { tables::ascii_space_character(c) /* C.1.1 */ || tables::non_ascii_space_character(c) /* C.1.2 */ || tables::ascii_control_character(c) /* C.2.1 */ || tables::non_ascii_control_character(c) /* C.2.2 */ || tables::private_use(c) /* C.3 */ || tables::non_character_code_point(c) /* C.4 */ || tables::surrogate_code(c) /* C.5 */ || tables::inappropriate_for_plain_text(c) /* C.6 */ || tables::inappropriate_for_canonical_representation(c) /* C.7 */ || tables::change_display_properties_or_deprecated(c) /* C.9 */ || tables::tagging_character(c) /* C.9 */ || prohibited_node_character(c) }); if let Some(c) = prohibited { return Err(Error(ErrorCause::ProhibitedCharacter(c))); } // A.6. Bidirectional Characters if is_prohibited_bidirectional_text(&normalized) { return Err(Error(ErrorCause::ProhibitedBidirectionalText)); } let unassigned = normalized .chars() .find(|&c| tables::unassigned_code_point(c)); if let Some(c) = unassigned { return Err(Error(ErrorCause::ProhibitedCharacter(c))); } Ok(Cow::Owned(normalized)) } ``` -------------------------------- ### x520prep Function Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Prepares a string according to Section 7 of ITU-T Recommendation X.520 (2019). This function handles mapping, normalization (NFKC), and prohibition of specific characters. It does not remove leading, trailing, or inner spaces. ```APIDOC ## x520prep(s: &str, case_fold: bool) -> Result, Error> ### Description Prepares a string according to the procedures described in Section 7 of [ITU-T Recommendation X.520 (2019)](https://www.itu.int/rec/T-REC-X.520-201910-I/en). Note that this function does _not_ remove leading, trailing, or inner spaces as described in Section 7.6, because the characters needing removal will vary across the matching rules and ASN.1 syntaxes used. ### Parameters - **s** (*&str*) - The input string to prepare. - **case_fold** (*bool*) - If true, performs case folding as part of normalization. ### Returns - `Result, Error>` - On success, returns a `Cow` containing the prepared string. On failure, returns an `Error`. ### Errors - `Error(ErrorCause::EmptyString)` - If the input string is empty. - `Error(ErrorCause::ProhibitedCharacter(char))` - If a prohibited character is found. - `Error(ErrorCause::StartsWithCombiningCharacter)` - If the string starts with a combining character. ### Examples ```rust use stringprep::x520prep; // Example 1: Basic usage with case folding let result1 = x520prep("foo@bar", true); match result1 { Ok(prepared_string) => println!("Prepared: {}", prepared_string), Err(e) => eprintln!("Error: {:?}", e), } // Example 2: Usage without case folding, with special characters let result2 = x520prep("J.\u{FE00} \u{9}W. \u{B}wuz h\u{0115}re", false); match result2 { Ok(prepared_string) => println!("Prepared: {}", prepared_string), Err(e) => eprintln!("Error: {:?}", e), } ``` ``` -------------------------------- ### map_windows Source: https://docs.rs/stringprep/0.1.5/stringprep/tables/struct.CaseFoldForNfkc.html Calls a function for each contiguous window of size `N` and returns an iterator over the results. This is a nightly-only experimental API. ```APIDOC ## fn map_windows(self, f: F) -> MapWindows ### Description Calls the given function `f` for each contiguous window of size `N` over `self` and returns an iterator over the outputs of `f`. Like `slice::windows()`, the windows during mapping overlap as well. ### Method `map_windows` ### Parameters - **f** (F) - A closure that takes a slice of `N` elements and returns a value `R`. ### Constraints This is a nightly-only experimental API. (`iter_map_windows`) ``` -------------------------------- ### partition Source: https://docs.rs/stringprep/0.1.5/stringprep/tables/struct.CaseFoldForNfkc.html Consumes an iterator and creates two collections based on a predicate. ```APIDOC ## fn partition(self, f: F) -> (B, B) ### Description Consumes an iterator, creating two collections from it. ### Method `partition` ### Parameters - **f** (F) - A closure that takes a reference to an item and returns a boolean. ### Type Parameters - **B**: Must implement `Default` and `Extend`. ``` -------------------------------- ### SASLprep String Preparation Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html Prepares a string using the SASLprep profile. Handles character mapping, normalization, and checks for prohibited characters and bidirectional text. Includes a fast path for ASCII text. ```rust pub fn saslprep(s: &str) -> Result, Error> { // fast path for ascii text if s.chars() .all(|c| c.is_ascii() && !tables::ascii_control_character(c)) { return Ok(Cow::Borrowed(s)); } // 2.1 Mapping let mapped = s .chars() .map(|c| { if tables::non_ascii_space_character(c) { ' ' } else { c } }) .filter(|&c| !tables::commonly_mapped_to_nothing(c)); // 2.2 Normalization let normalized = mapped.nfkc().collect::(); // 2.3 Prohibited Output let prohibited = normalized.chars().find(|&c| { tables::non_ascii_space_character(c) /* C.1.2 */ || tables::ascii_control_character(c) /* C.2.1 */ || tables::non_ascii_control_character(c) /* C.2.2 */ || tables::private_use(c) /* C.3 */ || tables::non_character_code_point(c) /* C.4 */ || tables::surrogate_code(c) /* C.5 */ || tables::inappropriate_for_plain_text(c) /* C.6 */ || tables::inappropriate_for_canonical_representation(c) /* C.7 */ || tables::change_display_properties_or_deprecated(c) /* C.8 */ || tables::tagging_character(c) /* C.9 */ }); if let Some(c) = prohibited { return Err(Error(ErrorCause::ProhibitedCharacter(c))); } // 2.4. Bidirectional Characters if is_prohibited_bidirectional_text(&normalized) { return Err(Error(ErrorCause::ProhibitedBidirectionalText)); } // 2.5 Unassigned Code Points let unassigned = normalized .chars() .find(|&c| tables::unassigned_code_point(c)); if let Some(c) = unassigned { return Err(Error(ErrorCause::ProhibitedCharacter(c))); } Ok(Cow::Owned(normalized)) } ``` -------------------------------- ### product Source: https://docs.rs/stringprep/0.1.5/stringprep/tables/struct.CaseFoldForNfkc.html Iterates over the entire iterator, multiplying all the elements. ```APIDOC ## fn product

(self) -> P ### Description Iterates over the entire iterator, multiplying all the elements. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```rust // Example usage not provided in source ``` ### Response #### Success Response (200) - `P`: The product of the elements. #### Response Example ```json // Example usage not provided in source ``` ``` -------------------------------- ### Resourceprep Profile Source: https://docs.rs/stringprep/0.1.5/src/stringprep/lib.rs.html The Resourceprep profile is used for preparing strings for use as resource identifiers in XMPP (Jabber). It is a simpler profile focusing on ASCII characters and basic normalization. ```APIDOC ## Resourceprep Profile ### Description Prepares a string with the Resourceprep profile of the stringprep algorithm, as defined in [RFC 3920, Appendix B][]. This profile is used for preparing strings for use as resource identifiers in XMPP (Jabber). [RFC 3920, Appendix B]: https://tools.ietf.org/html/rfc3920#appendix-B ### Function Signature `pub fn resourceprep(s: &str) -> Result, Error>` ### Steps: 1. **Mapping**: Removes characters mapped to nothing. 2. **Normalization**: Normalizes the string using NFKC. 3. **Prohibited Output**: Checks for and rejects characters that are prohibited according to the stringprep specification (e.g., non-ASCII spaces, control characters). ### Returns - `Ok(Cow<'_, str>)`: The prepared string if successful. - `Err(Error)`: An error if the string contains prohibited characters. ``` -------------------------------- ### nodeprep Source: https://docs.rs/stringprep/0.1.5/stringprep/all.html Performs the Nodprep profile for internationalized domain names. ```APIDOC ## nodeprep ### Description Performs the Nodprep profile for internationalized domain names. ### Function Signature `fn nodeprep(input: &str) -> Result` ```