MDL-44349 core_moodlelib: Improve word counting rules

Signed-off-by: Tony Butler <tonyjbutler@gmail.com>
MDL-44349 core_moodlelib: Add unit tests for count_words()

Signed-off-by: Tony Butler <tonyjbutler@gmail.com>