POSIX chose I rather than i as the case-insensitive flag for s///,
because apparently more seds support I than i. We're allegedly alone in
only supporting i. (On the Mac, sed supports neither.)

Strictly this isn't *currently* in POSIX, but it's been accepted for
issue 8.

Bug: https://austingroupbugs.net/view.php?id=779#c2050
---
 tests/sed.test   | 2 ++
 toys/posix/sed.c | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)
From ddeea4c144934dbfd8633910f6dcd910df3d84b3 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Fri, 27 Mar 2020 16:57:24 -0700
Subject: [PATCH] sed s///: support POSIX I as synonym for i

POSIX chose I rather than i as the case-insensitive flag for s///,
because apparently more seds support I than i. We're allegedly alone in
only supporting i. (On the Mac, sed supports neither.)

Strictly this isn't *currently* in POSIX, but it's been accepted for
issue 8.

Bug: https://austingroupbugs.net/view.php?id=779#c2050
---
 tests/sed.test   | 2 ++
 toys/posix/sed.c | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/sed.test b/tests/sed.test
index 98c109ad..613330d3 100755
--- a/tests/sed.test
+++ b/tests/sed.test
@@ -188,4 +188,6 @@ testing 'megabyte s/x/y/g (5 sec timeout)' "timeout 5 sed 's/x/y/g' | sha1sum" \
   '138c1fa7c3f64186203b0192fb4abdb33cb4e98a  -\n' '' "$X\n"
 unset X Y
 
+testing 's i and I' 'sed s/o/0/ig' "f00l F00L" "" "fool FOOL"
+
 # -i with $ last line test
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index fa40dbf5..0896959f 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -143,7 +143,7 @@ config SED
 
                  [0-9]    A number, substitute only that occurrence of pattern
                  g        Global, substitute all occurrences of pattern
-                 i        Ignore case when matching
+                 i/I      Ignore case when matching
                  p        Print the line if match was found and replaced
                  w [file] Write (append) line to file if match replaced
 
@@ -897,6 +897,7 @@ resume_s:
         if (isspace(*line) && *line != '\n') continue;
 
         if (0 <= (l = stridx("igp", *line))) command->sflags |= 1<<l;
+        else if (*line == 'I') command->sflags |= 1<<0;
         else if (!(command->sflags>>3) && 0<(l = strtol(line, &line, 10))) {
           command->sflags |= l << 3;
           line--;
-- 
2.26.0.rc2.310.g2932bb562d-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to