Crates.io | str-shorthand |
lib.rs | str-shorthand |
version | 0.2.0 |
source | src |
created_at | 2024-07-15 08:03:27.136616 |
updated_at | 2024-07-21 07:10:33.400499 |
description | A Rust crate that provides utility functions for string manipulation. Includes a function to bisect a string into two halves, handling multi-byte UTF-8 characters correctly. |
homepage | |
repository | https://github.com/klebs6/klebs-general |
max_upload_size | |
id | 1303564 |
size | 6,607 |
str-shorthand
is a Rust crate that provides utility functions for string manipulation. The initial version (0.1.0
) includes a function to bisect a string into two halves, handling multi-byte UTF-8 characters correctly.
Add str-shorthand
to your Cargo.toml
:
[dependencies]
str-shorthand = "0.1.0"
Then, include it in your project:
use str_shorthand::bisect;
The bisect function splits a string into two halves, ensuring correct handling of multi-byte UTF-8 characters.
use str_shorthand::bisect;
fn main() {
let text = "a😊bc😊";
let (first_half, second_half) = bisect(text);
println!("First half: {}", first_half); // Output: a😊b
println!("Second half: {}", second_half); // Output: c😊
}
bisect
Splits a string into two halves.
Signature:
pub fn bisect(text: &str) -> (&str, &str)
text
: A string slice to be split.
A tuple containing the two halves of the input string.
use str_shorthand::bisect;
let text = "abcdef";
let (first_half, second_half) = bisect(text);
assert_eq!(first_half, "abc");
assert_eq!(second_half, "def");
let text = "a😊b😊c";
let (first_half, second_half) = bisect(text);
assert_eq!(first_half, "a😊b");
assert_eq!(second_half, "😊c");
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.