[evolution-patches] g_strftime



an idea for implementing a workable strftime implementation that returns
a malloc'd buffer. also works around the fact that strftime is Broken By
Design (tm).

Jeff

-- 
Jeffrey Stedfast
Evolution Hacker - Ximian, Inc.
fejj ximian com  - www.ximian.com
char *
g_strftime (const char *fmt, const struct tm *tm)
{
	char *time_str, buf[64], fmt[4];
	const char *start, *inptr;
	GString *str;
	size_t n;
	
	fmt[0] = '%';
	fmt[2] = ' ';
	fmt[3] = '\0';
	
	str = g_string_new ("");
	
	inptr = format;
	while (*inptr) {
		start = inptr;
		
		while (*inptr != '%')
			inptr++;
		
		g_string_append_len (str, start, inptr - start);
		
		inptr++;
		if (*inptr == '%') {
			g_string_append_c (str, *inptr++);
		} else {
			fmt[1] = *inptr++;
			if ((n = strftime (buf, fmt, tm)) != 0) {
				g_string_append_len (str, buf, n - 1);
			}
		}
	}
	
	time_str = str->str;
	g_string_free (str, FALSE);
	
	return time_str;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]