%U - uppercase
%E - escape '"', "'" and '\' characters by inserting '\' before them.
-You can also limit a width of string by giving the number of max. characters
-after the '%' character. For example %1u gives the first character of
-username.
+You can take a substring of the variable by giving optional offset followed
+by '.' and width after the '%' character. For example %2u gives first two
+characters of the username. %2.1u gives third character of the username. If
+offset points outside the value, empty string is returned.
const struct var_expand_modifier *m;
const struct var_expand_table *t;
const char *var;
- unsigned int width;
+ unsigned int offset, width;
const char *(*modifier)(const char *);
for (; *str != '\0'; str++) {
str_append_c(dest, *str);
else {
str++;
+
+ /* [<offset>.]<width>[<modifier>]<variable> */
width = 0;
while (*str >= '0' && *str <= '9') {
width = width*10 + (*str - '0');
str++;
}
+ if (*str != '.')
+ offset = 0;
+ else {
+ offset = width;
+ width = 0;
+ str++;
+ while (*str >= '0' && *str <= '9') {
+ width = width*10 + (*str - '0');
+ str++;
+ }
+ }
+
modifier = NULL;
for (m = modifiers; m->key != '\0'; m++) {
if (m->key == *str) {
}
if (var != NULL) {
+ for (; *var != '\0' && offset > 0; offset--)
+ var++;
if (modifier != NULL)
var = modifier(var);
if (width == 0)