Add support for optional argument in -i option for in-place editing

This commit is contained in:
2026-07-08 19:52:31 -05:00
parent 0aa10adb4f
commit 572cbc9387
+12
View File
@@ -185,6 +185,18 @@ ParseResult OptionParser::parse(int argc, char **argv) const {
case 'r': case 'r':
result.options.extendedRegex = true; result.options.extendedRegex = true;
break; break;
case 'i':
// GNU sed accepts -i as an option with an optional argument. When
// it appears inside a short-option cluster, any remaining bytes in
// that argv word are the backup suffix, e.g. -nri~ == -n -r -i~.
// If there are no remaining bytes, it is plain in-place editing and
// does not consume the next argv entry.
result.options.inPlace = true;
if (j + 1 < arg.size()) {
result.options.inPlaceSuffix = arg.substr(j + 1);
j = arg.size();
}
break;
case 'z': case 'z':
result.options.nullData = true; result.options.nullData = true;
break; break;