Tiny shrink (10 bytes): Re: [git commit] sed: support \r in s command
Pascal Bellard
pascal.bellard at ads-lu.com
Tue May 3 08:11:37 UTC 2011
My 2p...
text data bss dec hex filename
5899 0 0 5899 170b busybox.org/editors/sed.o
5889 0 0 5889 1701 busybox/editors/sed.o
--- busybox.org/editors/sed.c Tue May 3 00:52:22 2011
+++ busybox/editors/sed.c Tue May 3 09:49:54 2011
@@ -215,12 +215,15 @@
static char *copy_parsing_escapes(const char *string, int len)
{
+ const char *s;
char *dest = xmalloc(len + 1);
- parse_escapes(dest, string, len, 'n', '\n');
/* GNU sed also recognizes \t and \r */
- parse_escapes(dest, dest, strlen(dest), 't', '\t');
- parse_escapes(dest, dest, strlen(dest), 'r', '\r');
+ for (s = "\nn\tt\rr"; *s; s += 2) {
+ parse_escapes(dest, string, len, s[1], s[0]);
+ string = dest;
+ len = strlen(dest);
+ }
return dest;
}
>
> commit:
> http://git.busybox.net/busybox/commit/?id=6a0abcc02f0773f32f2d31b3532eec1b11e1f67d
> branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
>
> function old new delta
> copy_parsing_escapes 65 91 +26
>
> Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
> ---
> editors/sed.c | 3 ++-
> testsuite/sed.tests | 3 +++
> 2 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/editors/sed.c b/editors/sed.c
> index 9e27e3e..11c4763 100644
> --- a/editors/sed.c
> +++ b/editors/sed.c
> @@ -218,8 +218,9 @@ static char *copy_parsing_escapes(const char *string,
> int len)
> char *dest = xmalloc(len + 1);
>
> parse_escapes(dest, string, len, 'n', '\n');
> - /* GNU sed also recognizes \t */
> + /* GNU sed also recognizes \t and \r */
> parse_escapes(dest, dest, strlen(dest), 't', '\t');
> + parse_escapes(dest, dest, strlen(dest), 'r', '\r');
> return dest;
> }
>
> diff --git a/testsuite/sed.tests b/testsuite/sed.tests
> index 395372a..e9d0ed6 100755
> --- a/testsuite/sed.tests
> +++ b/testsuite/sed.tests
> @@ -287,6 +287,9 @@ testing "sed -i with address modifies all files, not
> only first" \
> "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input
> input2; rm input2" \
> "bar\nbar\n" "foo\n" ""
>
> +testing "sed understands \r" \
> + "sed 's/r/\r/'" \
> + "\rrr\n" "" "rrr\n"
>
> # testing "description" "arguments" "result" "infile" "stdin"
>
> --
> 1.7.3.4
>
> _______________________________________________
> busybox-cvs mailing list
> busybox-cvs at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox-cvs
>
-pascal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sed.u
Type: application/octet-stream
Size: 774 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20110503/ad0ad2ea/attachment.obj>
More information about the busybox
mailing list