wordCount method
Counts words using whitespace as delimiters.
Leading/trailing whitespace is trimmed. Empty string returns 0.
Example:
'hello world'.wordCount(); // 2
' a b '.wordCount(); // 2
Implementation
@useResult
int wordCount() {
if (isEmpty) return 0;
final String trimmed = trim();
if (trimmed.isEmpty) return 0;
return trimmed.split(_wordBoundary).where((String s) => s.isNotEmpty).length;
}