https://github.com/magiclen/words-count
Count the words and characters, with or without whitespaces.
https://github.com/magiclen/words-count
rust
Last synced: about 1 year ago
JSON representation
Count the words and characters, with or without whitespaces.
- Host: GitHub
- URL: https://github.com/magiclen/words-count
- Owner: magiclen
- License: mit
- Created: 2020-08-14T11:06:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-24T21:26:17.000Z (about 2 years ago)
- Last Synced: 2025-03-24T17:55:20.735Z (about 1 year ago)
- Topics: rust
- Language: Rust
- Homepage:
- Size: 28.3 KB
- Stars: 12
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Words Count
====================
[](https://github.com/magiclen/words-count/actions/workflows/ci.yml)
Count the words and characters, with or without whitespaces.
The algorithm is roughly aligned with the way LibreOffice is counting words. This means that it does not exactly match the [Unicode Text Segmentation](https://unicode.org/reports/tr29/#Word_Boundaries) standard.
## Examples
```rust
use words_count::WordsCount;
assert_eq!(WordsCount {
words: 20,
characters: 31,
whitespaces: 2,
cjk: 18,
}, words_count::count("Rust是由 Mozilla 主導開發的通用、編譯型程式語言。"));
```
```rust
let result = words_count::count_separately("apple banana apple");
assert_eq!(2, result.len());
assert_eq!(Some(&2), result.get("apple"));
```
## Crates.io
https://crates.io/crates/words-count
## Documentation
https://docs.rs/words-count
## License
[MIT](LICENSE)