Improvements to Str::words

* Fix possible error with certain inputs (see #1076)
* Uniformize handling of leading and trailing spaces
* Add unit tests