dovecot-2.2: liblib: Added negative %variable lengths to count b...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Mar 17 14:57:56 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/97d31cbbfe01
changeset: 17159:97d31cbbfe01
user: Timo Sirainen <tss at iki.fi>
date: Mon Mar 17 16:57:21 2014 +0200
description:
liblib: Added negative %variable lengths to count backwards from the end of the value.
For example %0.-2 for "12345" returns "123".
Patch by Norbert Weinhold / Open-Xchange.
diffstat:
src/lib/var-expand.c | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)
diffs (65 lines):
diff -r 20a25e17bc3e -r 97d31cbbfe01 src/lib/var-expand.c
--- a/src/lib/var-expand.c Wed Mar 12 14:09:14 2014 +0200
+++ b/src/lib/var-expand.c Mon Mar 17 16:57:21 2014 +0200
@@ -19,7 +19,7 @@
struct var_expand_context {
int offset;
- unsigned int width;
+ int width;
bool zero_padding;
};
@@ -268,7 +268,8 @@
}
if (*str == '.') {
- ctx.offset = sign * (int)ctx.width;
+ ctx.offset = sign * ctx.width;
+ sign = 1;
ctx.width = 0;
str++;
@@ -280,11 +281,16 @@
ctx.zero_padding = TRUE;
str++;
}
+ if (*str == '-') {
+ sign = -1;
+ str++;
+ }
while (*str >= '0' && *str <= '9') {
ctx.width = ctx.width*10 + (*str - '0');
str++;
}
+ ctx.width = sign * ctx.width;
}
modifier_count = 0;
@@ -350,11 +356,13 @@
}
if (ctx.width == 0)
str_append(dest, var);
- else if (!ctx.zero_padding)
+ else if (!ctx.zero_padding) {
+ if (ctx.width < 0)
+ ctx.width = strlen(var) - (-ctx.width);
str_append_n(dest, var, ctx.width);
- else {
+ } else {
/* %05d -like padding. no truncation. */
- size_t len = strlen(var);
+ int len = strlen(var);
while (len < ctx.width) {
str_append_c(dest, '0');
ctx.width--;
@@ -392,7 +400,7 @@
if (str[i] == '.') {
i++;
- while (str[i] >= '0' && str[i] <= '9')
+ while ((str[i] >= '0' && str[i] <= '9') || str[i] == '-')
i++;
}
More information about the dovecot-cvs
mailing list