strfuncs.c revision 1d9f94199ff5c49cf9df18fd0c9eb85c0fb77a6c
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen strfuncs.c : String manipulation functions (note: LGPL, because the )
c8d88cb784cc7f7edcdc97f8b24b243eb1bba7aaTimo Sirainen Copyright (C) 2001-2002 Timo Sirainen
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen printf_string_upper_bound() code is taken from GLIB:
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen Modified by the GLib Team and others 1997-1999.
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen This library is free software; you can redistribute it and/or
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen modify it under the terms of the GNU Library General Public
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen License as published by the Free Software Foundation; either
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen version 2 of the License, or (at your option) any later version.
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen This library is distributed in the hope that it will be useful,
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen Library General Public License for more details.
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen You should have received a copy of the GNU Library General Public
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen License along with this library; if not, write to the
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen Free Software Foundation, Inc., 59 Temple Place - Suite 330,
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen Boston, MA 02111-1307, USA.
a1fff894178eb4279a3acb44948c1ba98db104deTimo Sirainenstatic void *tp_malloc(Pool pool __attr_unused__, size_t size)
a1fff894178eb4279a3acb44948c1ba98db104deTimo Sirainen/* multiply with base2 exponent to get base10 exponent (nomal numbers) */
a1fff894178eb4279a3acb44948c1ba98db104deTimo Sirainen#define G_LOG_2_BASE_10 (0.30102999566398119521)
86441ffc028f11857152c15fe7b0d24ff0874504Timo Sirainen#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
86441ffc028f11857152c15fe7b0d24ff0874504Timo Sirainen#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
86441ffc028f11857152c15fe7b0d24ff0874504Timo Sirainentypedef struct
86441ffc028f11857152c15fe7b0d24ff0874504Timo Sirainen int alternate_format, zero_padding, adjust_left, locale_grouping;
86441ffc028f11857152c15fe7b0d24ff0874504Timo Sirainen int add_space, add_sign, possible_sign, seen_precision;
86441ffc028f11857152c15fe7b0d24ff0874504Timo Sirainensize_t printf_string_upper_bound(const char *format, va_list args)
86441ffc028f11857152c15fe7b0d24ff0874504Timo Sirainen register char c = *format++;
be1749e2421dea6465f9096fd35b28b2500d06e4Timo Sirainen if (c != '%')
be1749e2421dea6465f9096fd35b28b2500d06e4Timo Sirainen else /* (c == '%') */
be1749e2421dea6465f9096fd35b28b2500d06e4Timo Sirainen unsigned int conv_len = 0;
f43734e772a94c8d2b684b59c212fecf66122d15Stephan Bosch unsigned int v_uint;
f43734e772a94c8d2b684b59c212fecf66122d15Stephan Bosch /* beware of positional parameters
f43734e772a94c8d2b684b59c212fecf66122d15Stephan Bosch i_panic("unable to handle positional parameters (%%n$)");
f43734e772a94c8d2b684b59c212fecf66122d15Stephan Bosch /* parse flags
f43734e772a94c8d2b684b59c212fecf66122d15Stephan Bosch /* parse output size specifications
1f35f54096589b0fdb04bfac4d079d06b43f2a74Timo Sirainen spec.precision = I_MAX (spec.precision, v_uint);
1f35f54096589b0fdb04bfac4d079d06b43f2a74Timo Sirainen spec.min_width = I_MAX (spec.min_width, v_uint);
1f35f54096589b0fdb04bfac4d079d06b43f2a74Timo Sirainen /* forget about negative precision */
1f35f54096589b0fdb04bfac4d079d06b43f2a74Timo Sirainen spec.precision = I_MAX ((int)spec.precision, v_int);
1f35f54096589b0fdb04bfac4d079d06b43f2a74Timo Sirainen spec.min_width = I_MAX ((int)spec.min_width, v_int);
1f35f54096589b0fdb04bfac4d079d06b43f2a74Timo Sirainen /* parse type modifiers
c8d88cb784cc7f7edcdc97f8b24b243eb1bba7aaTimo Sirainen /* else, fall through */
c8d88cb784cc7f7edcdc97f8b24b243eb1bba7aaTimo Sirainen /* parse output conversions
c8d88cb784cc7f7edcdc97f8b24b243eb1bba7aaTimo Sirainen /* fall through */
12ff27eadb44c6877298d3e214c7039342669669Timo Sirainen /* fall through */
be1749e2421dea6465f9096fd35b28b2500d06e4Timo Sirainen /* fall through */
#if SIZEOF_LONG_LONG > 0
#ifdef HAVE_LONG_DOUBLE
if (!v_string)
if (HONOUR_LONGS)
while (!conv_done);
return len;
const char *errstr;
char *buf;
return buf;
return fmt;
#ifdef HAVE_VSNPRINTF
int ret;
t_push();
t_pop();
if (ret < 0) {
return ret;
char *buf;
int len;
t_push();
t_pop();
return len;
void *mem; \
len++; \
len++; \
return mem; \
} STMT_END
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL; \
} STMT_END
char *mem;
return mem;
char *mem;
return mem;
char *mem;
return NULL;
len = 0;
len++;
return mem;
char *ret;
return ret;
const char *ret;
return ret;
char *ret;
return NULL;
return ret;
char *ret;
t_push();
t_pop();
return ret;
const char *str;
char *temp;
return NULL;
if (len == 0)
return temp;
const char *temp;
char *ret;
return ret;
const char *ret;
return ret;
if (*p == cutchar)
return str;
return FALSE;
return FALSE;
str++;
return TRUE;
*p = i_toupper(*p);
return str;
*p = i_tolower(*p);
return str;
char *ret;
return NULL;
(*str)++;
(*str)++;
return ret;
char *dest;
int len;
len = 0;
while (*array) {
len++;
array++;
return len;
int index;
return index;
char **array;
char *str;
str++;
return (char *const *) array;
const char *arg;
char *data;
return NULL;
return data;
if (number == 0)
if (size == 0)
pos++;