Simplify shrink macro implementation
Less code and easier to understand.
This commit is contained in:
parent
efc3f10754
commit
3c793a653d
|
@ -1184,23 +1184,19 @@ static void doFoo(MacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed)
|
||||||
* shrink body by removing all leading and trailing whitespaces and
|
* shrink body by removing all leading and trailing whitespaces and
|
||||||
* reducing intermediate whitespaces to a single space character.
|
* reducing intermediate whitespaces to a single space character.
|
||||||
*/
|
*/
|
||||||
buf = xstrdup(argv[1]);
|
char *p, c, last_c = ' ';
|
||||||
size_t i = 0, j = 0;
|
buf = b = p = xstrdup(argv[1]);
|
||||||
size_t buflen = strlen(buf);
|
while ((c = *p++) != 0) {
|
||||||
int was_space = 0;
|
if (risspace(c)) {
|
||||||
while (i < buflen) {
|
if (last_c == ' ')
|
||||||
if (risspace(buf[i])) {
|
continue;
|
||||||
was_space = 1;
|
c = ' ';
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
} else if (was_space) {
|
|
||||||
was_space = 0;
|
|
||||||
if (j > 0) /* remove leading blanks at all */
|
|
||||||
buf[j++] = ' ';
|
|
||||||
}
|
}
|
||||||
buf[j++] = buf[i++];
|
*b++ = last_c = c;
|
||||||
}
|
}
|
||||||
buf[j] = '\0';
|
if (b != buf && b[-1] == ' ')
|
||||||
|
b--;
|
||||||
|
*b = 0;
|
||||||
b = buf;
|
b = buf;
|
||||||
} else if (rstreq("quote", me->name)) {
|
} else if (rstreq("quote", me->name)) {
|
||||||
rasprintf(&buf, "%c%s%c", 0x1f, argv[1], 0x1f);
|
rasprintf(&buf, "%c%s%c", 0x1f, argv[1], 0x1f);
|
||||||
|
|
Loading…
Reference in New Issue