From c51a8c3c5e510b05bdc8f71cd8099927ce2c7c53 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Jul 2010 13:17:36 -0500 Subject: Generating the bitmask of posibilities from the format string. --- src/indicator-datetime.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 171ee2f..9a29324 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -624,6 +624,43 @@ const static strftime_type_t strftime_type[] = { #define FAT_NUMBER 8 +/* Looks through the characters in the format string to + ensure that we can figure out which of the things we + need to check in determining the length. */ +static gint +generate_strftime_bitmask (IndicatorDatetime * self) +{ + gint retval = 0; + glong strlength = g_utf8_strlen(self->priv->time_string, 0); + gint i; + + for (i = 0; i < strlength; i++) { + if (self->priv->time_string[i] == '%' && i + 1 < strlength) { + gchar evalchar = self->priv->time_string[i + 1]; + + /* If we're using alternate formats we need to skip those characters */ + if (evalchar == 'E' || evalchar == 'O') { + if (i + 2 < strlength) { + evalchar = self->priv->time_string[i + 2]; + } else { + continue; + } + } + + /* Let's look at that character in the table */ + int j; + for (j = 0; strftime_type[j].character != 0; j++) { + if (strftime_type[j].character == evalchar) { + retval |= strftime_type[j].mask; + break; + } + } + } + } + + return retval; +} + /* Try to get a good guess at what a maximum width of the entire string would be. */ static void -- cgit v1.2.3