2 unstable releases
0.2.0 | Jul 21, 2024 |
---|---|
0.1.0 | Jul 15, 2024 |
#5 in #multi-byte
58 downloads per month
6KB
65 lines
str-shorthand
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.
Features
- Bisect Function: Automatically splits a string into two halves, ensuring UTF-8 safety and correctness.
Installation
Add str-shorthand
to your Cargo.toml
:
[dependencies]
str-shorthand = "0.1.0"
Then, include it in your project:
use str_shorthand::bisect;
Usage
The bisect function splits a string into two halves, ensuring correct handling of multi-byte UTF-8 characters.
Example
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😊
}
Functions
bisect
Splits a string into two halves.
Signature:
pub fn bisect(text: &str) -> (&str, &str)
Parameters:
text
: A string slice to be split.
Returns:
A tuple containing the two halves of the input string.
Examples:
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");
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.