possess method
Returns the possessive form of this string (e.g., "John's", "boss'").
Trims the input before processing. For words ending in 's':
- US style (default): adds apostrophe only → "boss'"
- Non-US style: adds apostrophe-s → "boss's"
All other words get apostrophe-s → "John's".
Args:
isLocaleUS: If true (default), uses US possessive style for words ending in 's'.
Returns: The possessive form of the trimmed string, or the original if empty.
Example:
'John'.possess(); // "John's"
'boss'.possess(); // "boss'" (US style)
'boss'.possess(isLocaleUS: false); // "boss's" (non-US)
' James '.possess(); // "James'" (trimmed)
Implementation
String possess({bool isLocaleUS = true}) {
if (isEmpty) return this;
final String base = trim();
if (base.isEmpty) return base;
final String last = base.lastChars(1).toLowerCase();
if (last == 's') {
return isLocaleUS ? "$base'" : "$base's";
}
return "$base's";
}