str-shorthand

Crates.iostr-shorthand
lib.rsstr-shorthand
version0.2.0
sourcesrc
created_at2024-07-15 08:03:27.136616
updated_at2024-07-21 07:10:33.400499
descriptionA 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
repositoryhttps://github.com/klebs6/klebs-general
max_upload_size
id1303564
size6,607
(klebs6)

documentation

README

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.

Commit count: 110

cargo fmt