About

Bwrap is a fast, lightweight, embedded environment-friendly library for wrapping text. While Bwrap offers great flexibility in wrapping text, neither resource consumption nor performance compromises:

  1. No heap allocation happens by default.

  2. The time/space complexity is O(n) by default, or O(n(p+a)) if there is appending/prepending. (n, p, a is the number of input bytes, prepended bytes, and appended bytes respectively)

For the sake of readability, we (b)etter wrap our text.

Benchmark

Below are the performance comparisons among several text-wrapping libraries in different dimensions:

Time elapsed:

Memory usage:

Note:

  1. Details about benchmark samples or methods are elaborated in bench-wrap-libs.

  2. The benchmark results above are obtained on an i7u/16G machine and are for reference only. Different machines or idle system resource might generate different results.

Examples

Multiple languages

Bwrap suuport multiple languages, it categorizes languages into two categories: space-sensitive and space-insensitive. The former is for the languages that depend on ASCII SPACE to delimit words, such as English, Ukrainian, Greek and so on. The latter is for the languages that are space-insensitive, such as Chinese, Japanese, Thai and so on.

English, Ukrainian, Greek, etc.

Chinese, Japanese, Thai, etc.

Append/prepend

Bwrap can append or prepend whatever string to newly added newline character. With this feature, one can effectively achieve indentation, line trailing notation or similar.

Indentation

Original:

Here is our schedule: - Do A, and do B, and do C, and do D, and do E, and do F - Do G, and do H, and do I, and do J, and do K, and do L

Wrapped:

Here is our schedule: - Do A, and do B, and do C, and do D, and do E, and do F - Do G, and do H, and do I, and do J, and do K, and do L

Source code:

```rust use bwrap::{EasyWrapper, ExistNlPref, WrapStyle::NoBrk};

let line = "Here is our schedule:\n- Do A, and do B, and do C, and do D, and do E, and do F\n- Do G, and do H, and do I, and do J, and do K, and do L"; println!("ORIGINAL:\n\n{}\n", line); let mut w = EasyWrapper::new(line, 35).unwrap(); let wrapped = w.wrapusestyle(NoBrk(Some(" "), ExistNlPref::KeepTrailSpc)).unwrap(); println!("WRAPPED:\n\n{}", wrapped); ```

Trailing notation

Original:

VGhpcyBpcyBhIHNlY3JldCBtZXNzYWdlLCBwbGVhc2UgZGVsZXRlIGFmdGVyIHJlYWQK

Wrapped:

VGhpcyBpcy | BhIHNlY3Jl | dCBtZXNzYW | dlLCBwbGVh | c2UgZGVsZX | RlIGFmdGVy | IHJlYWQK

Source code:

```rust use bwrap::{EasyWrapper, WrapStyle::MayBrk};

let line = "VGhpcyBpcyBhIHNlY3JldCBtZXNzYWdlLCBwbGVhc2UgZGVsZXRlIGFmdGVyIHJlYWQK"; println!("ORIGINAL:\n\n{}\n", line); let mut w = EasyWrapper::new(line, 10).unwrap(); let wrapped = w.wrapusestyle(MayBrk(Some(" |"), None)).unwrap(); println!("WRAPPED:\n\n{}", wrapped); ```

License

Bwrap can be licensed under either MIT License or GNU General Public License Version 3.0. The choice is up to the recipient.