unwrap method
Removes prefix and suffix from the string if they exist.
If suffix is not provided, prefix is used as suffix.
Examples:
- 'hello'.unwrap("*") returns 'hello'
- ''.unwrap('<', '>') returns 'html'
Implementation
String unwrap(String prefix, [String? suffix]) {
suffix ??= prefix;
if (startsWith(prefix)) {
return substring(
prefix.length,
endsWith(suffix) ? length - suffix.length : length,
);
}
return endsWith(suffix) ? substring(0, length - suffix.length) : this;
}