removeMatchingWrappingBrackets method
Returns a new string with the outer matching bracket pair removed. Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
String removeMatchingWrappingBrackets() {
if (!isBracketWrapped()) return this;
// Slice by grapheme count, not code-unit `length`: `substringSafe` is
// grapheme-indexed, so a code-unit length over astral content removed the
// wrong span (e.g. '(😀)' kept the trailing bracket).
final int graphemeCount = characters.length;
return substringSafe(1, graphemeCount - 1);
}