word_count

Crates.ioword_count
lib.rsword_count
version0.1.0
sourcesrc
created_at2015-03-30 19:20:44.683956
updated_at2015-12-11 23:59:34.806356
descriptionCount the words in a string.
homepagehttps://github.com/Leo2807/word_count/
repositoryhttps://github.com/Leo2807/word_count/
max_upload_size
id1740
size10,720
Leander (Leo2807)

documentation

README

% Word count

word_count

This is a program/library to count the words in a string. Use it to analyze texts of your favorite author.

Examples

Executable:

$ echo 'I like cookies. Mmm... Cookies.' | word_count
'cookies':  2
'mmm':      1
'like':     1
'i':        1

Library:

extern crate lib_word_count;

fn main() {

    let mut word_index = Vec::new();
    let input = "I like cookies. Mmm... Cookies.";

    lib_word_count::count_words(input, &mut word_index);

    assert_eq!(word_index.len(), 4);

    assert_eq!(word_index[0].word, "cookies".to_string);
    assert_eq!(word_index[1].word, "i".to_string);
    assert_eq!(word_index[2].word, "like".to_string);
    assert_eq!(word_index[3].word, "mmm".to_string);

    assert_eq!(word_index[0].appeared, 2);
    assert_eq!(word_index[1].appeared, 1);
    assert_eq!(word_index[2].appeared, 1);
    assert_eq!(word_index[3].appeared, 1);
}
Commit count: 21

cargo fmt