Hello,
Actualy, Format() can only use "s", "i", "u", "li" and "lu". If you want to use
another parser this will return an error.
So you can use, if there is another parser, vsnprintf directly.
For example, see this this function :
int myvsnprintf(char *buf, size_t size, const char *format, va_list vl)
{
register char *p = buf;
register const char *fmt = format;
const char *end = p + size - 1; /* -1 pour le \0 */
char t;
while((t = *fmt++) && p < end) /* %sa (t = %, *pattern = s) */
{
if(t == '%')
{
t = *fmt++; /* on drop le formateur (t = s, *pattern =
a) */
if(t == 's')
{/* copie de la string */
register const char *tmps = va_arg(vl, char *);
while(*tmps && p < end) *p++ = *tmps++;
continue;
}
if(t == 'd')
{
int tmpi = va_arg(vl, int), pos = 31;
char bufi[32];
if(tmpi <= 0)
{
if(!tmpi)
{
*p++ = '0';
continue;
}
*p++ = '-';
tmpi = -tmpi;
}
while(tmpi) /* on converti une int en base 10
en string */
{/* écriture dans l'ordre inverse 51 > ' 1' >
' 51'*/
bufi[pos--] = '0' + (tmpi % 10);
tmpi /= 10;
}
while(pos < sizeof bufi -1 && p < end) *p++ =
bufi[++pos];
continue;
}
if(t == 'c')
{
*p++ = (char) va_arg(vl, int);
continue;
}
if(t != '%')
{/* on sous traite le reste à vsnprintf (-2 because of
the %*)
on laisse vsnprintf écrire le \0 d'où le + 1 */
int i = vsnprintf(p, end - p + 1, fmt - 2, vl);
p += i < end - p ? i : end - p; /* si i >= size
: overflow bloqué */
break;
}
}
*p++ = t;
}
*p = '\0';
return p - end + size - 1; /* on ne retourne que la taille
effectivement utilisée */
}
It's a C function, but this shows there general idea. If parsers are not 's',
'd' or 'c', it will call vsnprintf function.
Progs.