[evolution-patches] g_strftime
- From: Jeffrey Stedfast <fejj ximian com>
- To: Mike Kestner <mkestner ximian com>, evolution-patches ximian com
- Subject: [evolution-patches] g_strftime
- Date: 23 May 2003 18:13:23 -0400
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]