possess method
Returns the possessive form of this string (e.g., "John's", "boss'").
When isLocaleUS is true (default), words ending in 's' get only an
apostrophe ("boss'"). When false, they get apostrophe-s ("boss's").
Example:
'John'.possess(); // "John's"
'boss'.possess(); // "boss'" (US style)
'boss'.possess(isLocaleUS: false); // "boss's" (non-US)
Implementation
@useResult
String possess({bool isLocaleUS = true}) {
if (isEmpty) {
return this;
}
final String base = trim();
if (base.isEmpty) {
return base;
}
final String lastChar = base.lastChars(1).toLowerCase();
if (lastChar == 's') {
return isLocaleUS ? '$base\'' : '$base\'s';
}
return '$base\'s';
}