#word-count #word #count #counter #character #word-counter

simple-word-count

a simple word count function, try to get same result with Microsoft Office Word application

2 releases

0.1.1 Mar 2, 2024
0.1.0 Mar 2, 2024

#1426 in Text processing

Download history 2/week @ 2024-07-18 16/week @ 2024-07-25 3/week @ 2024-09-12 9/week @ 2024-09-19 18/week @ 2024-09-26 21/week @ 2024-10-03

51 downloads per month

MIT/Apache

9KB
71 lines

Description

a simple word count function, try to get same result with Microsoft Office Word application.
Not guarantee same result on special characters. Such like Emoji “😘😦😒” is count 1 in Microsoft Office Word, but 3 by word_count.

Examples

use simple_word_count::word_count;

fn main() {
    assert_eq!(word_count("helloworld"), 1);
    assert_eq!(word_count("hello world"), 2);
    assert_eq!(word_count("hello, world"), 2);
    assert_eq!(word_count("h e l l o	w o r l d"), 10);
    assert_eq!(word_count("hi......"), 1);
    assert_eq!(word_count("hello, world | 你好,世界"), 8);
    assert_eq!(word_count("你好世界"), 4);
    assert_eq!(word_count("你好,世界"), 5);
    assert_eq!(word_count("你 好 世 界"), 4);
    assert_eq!(word_count("你好。。。。"), 6);
    assert_eq!(word_count("a=b+c-d"), 1);
    assert_eq!(word_count("a = b + c - d"), 7);
    assert_eq!(word_count("123"), 1);
    assert_eq!(word_count("123.456"), 1);
    assert_eq!(word_count("123..456"), 1);
    assert_eq!(word_count("123.456."), 1);
    assert_eq!(word_count("123 456"), 2);
    assert_eq!(word_count("1+1=2"), 1);
    assert_eq!(word_count("1 + 1 = 2"), 5);
    assert_eq!(word_count("&&%%$$¥¥"), 3);
    assert_eq!(word_count("<>《》"), 3);
}

No runtime deps