struct var_expand_context {
int offset;
- unsigned int width;
+ int width;
bool zero_padding;
};
}
if (*str == '.') {
- ctx.offset = sign * (int)ctx.width;
+ ctx.offset = sign * ctx.width;
+ sign = 1;
ctx.width = 0;
str++;
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;
}
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--;
if (str[i] == '.') {
i++;
- while (str[i] >= '0' && str[i] <= '9')
+ while ((str[i] >= '0' && str[i] <= '9') || str[i] == '-')
i++;
}