Bernhard Reutner-Fischer wrote:
>ah oh in the old code we double increment (only) if the first was a
>backslash _not_ followed by a nul.
>hmz. So is there a more elegant way to express that which i don't see
>right now?
I suspect the inelegance is inherent. Here's the current code:
1 while (*s) {
2 if (*s == c)
3 return (char *)s;
4 if (*s == '\\')
5 if (*++s == '\0')
6 break;
7 s++;
8 }
It has the advantage that all the special magic is in lines 4-6.
If you ignore them it's just a standard strchr().
1 while (*s) {
2 if (*s == c)
3 return (char *)s;
4 if (*s++ == '\\')
5 if (*s++ == '\0')
6 break;
7 }
This is more uniform but adds 6 bytes of bloat.
1 while (*s) {
2 if (*s == c)
3 return (char *)s;
4 if (*s++ == '\\')
5 if (*s != '\0')
6 s++;
7 }
This makes it clearer that we only skip the character following the
backslash if it's not NUL and it avoids the break. 5 bytes of bloat.
Dietmar's suggestion is indeed equivalent and adds no bloat. But,
in my opinion, needs more effort to understand.
If the current code is unclear maybe it needs a comment:
// skip char after backslash, unless it's NUL
Ron
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox