/pidgin/main: 2e75223c078e: Do some proper parsing of UTS-35 dat...

Elliott Sales de Andrade qulogic at pidgin.im
Fri Jun 15 03:12:26 EDT 2012


Changeset: 2e75223c078e3f0cefda710304d099234c4687bd
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2012-06-15 00:23 -0400
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/2e75223c078e

Description:

Do some proper parsing of UTS-35 date formats.

This doesn't totally replace everything yet, but it should at least
parse everything.

diffstat:

 libpurple/util.c |  359 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 libpurple/util.h |   13 +
 pidgin/gtkconv.c |   41 +++--
 3 files changed, 395 insertions(+), 18 deletions(-)

diffs (truncated from 484 to 300 lines):

diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -929,6 +929,365 @@
 	return retval;
 }
 
+char *
+purple_uts35_to_str(const char *format, size_t len, struct tm *tm)
+{
+	GString *string;
+	int i, count;
+
+	if (tm == NULL) {
+		time_t now = time(NULL);
+		tm = localtime(&now);
+	}
+
+	string = g_string_sized_new(len);
+	i = 0;
+	while (i < len) {
+		count = 1;
+		while ((i + count) < len && format[i] == format[i+count])
+			count++;
+
+		switch (format[i]) {
+			/* Era Designator */
+			case 'G':
+				if (count <= 3) {
+					/* Abbreviated */
+				} else if (count == 4) {
+					/* Full */
+				} else if (count >= 5) {
+					/* Narrow */
+					count = 5;
+				}
+				break;
+
+
+			/* Year */
+			case 'y':
+				if (count == 2) {
+					/* Two-digits only */
+					g_string_append(string, purple_utf8_strftime("%y", tm));
+				} else {
+					/* Zero-padding */
+					char *tmp = g_strdup_printf("%%0%dY", count);
+					g_string_append(string, purple_utf8_strftime(tmp, tm));
+					g_free(tmp);
+				}
+				break;
+
+			/* Year (in "Week of Year" based calendars) */
+			case 'Y':
+				if (count == 2) {
+					/* Two-digits only */
+				} else {
+					/* Zero-padding */
+				}
+				break;
+
+			/* Extended Year */
+			case 'u':
+				break;
+
+			/* Cyclic Year Name */
+			case 'U':
+				if (count <= 3) {
+					/* Abbreviated */
+				} else if (count == 4) {
+					/* Full */
+				} else if (count >= 5) {
+					/* Narrow */
+					count = 5;
+				}
+				break;
+
+
+			/* Quarter */
+			case 'Q':
+				if (count <= 2) {
+					/* Numerical */
+				} else if (count == 3) {
+					/* Abbreviation */
+				} else if (count >= 4) {
+					/* Full */
+					count = 4;
+				}
+				break;
+
+			/* Stand-alone Quarter */
+			case 'q':
+				if (count <= 2) {
+					/* Numerical */
+				} else if (count == 3) {
+					/* Abbreviation */
+				} else if (count >= 4) {
+					/* Full */
+					count = 4;
+				}
+				break;
+
+			/* Month */
+			case 'M':
+				if (count <= 2) {
+					/* Numerical */
+					g_string_append(string, purple_utf8_strftime("%m", tm));
+				} else if (count == 3) {
+					/* Abbreviation */
+					g_string_append(string, purple_utf8_strftime("%b", tm));
+				} else if (count == 4) {
+					/* Full */
+					g_string_append(string, purple_utf8_strftime("%B", tm));
+				} else if (count >= 5) {
+					g_string_append_len(string, purple_utf8_strftime("%b", tm), 1);
+					count = 5;
+				}
+				break;
+
+			/* Stand-alone Month */
+			case 'L':
+				if (count <= 2) {
+					/* Numerical */
+					g_string_append(string, purple_utf8_strftime("%m", tm));
+				} else if (count == 3) {
+					/* Abbreviation */
+					g_string_append(string, purple_utf8_strftime("%b", tm));
+				} else if (count == 4) {
+					/* Full */
+					g_string_append(string, purple_utf8_strftime("%B", tm));
+				} else if (count >= 5) {
+					g_string_append_len(string, purple_utf8_strftime("%b", tm), 1);
+					count = 5;
+				}
+				break;
+
+			/* Ignored */
+			case 'l':
+				break;
+
+
+			/* Week of Year */
+			case 'w':
+				g_string_append(string, purple_utf8_strftime("%W", tm));
+				count = MIN(count, 2);
+				break;
+
+			/* Week of Month */
+			case 'W':
+				count = 1;
+				break;
+
+
+			/* Day of Month */
+			case 'd':
+				g_string_append(string, purple_utf8_strftime("%d", tm));
+				count = MIN(count, 2);
+				break;
+
+			/* Day of Year */
+			case 'D':
+				g_string_append(string, purple_utf8_strftime("%j", tm));
+				count = MIN(count, 3);
+				break;
+
+			/* Day of Year in Month */
+			case 'F':
+				count = 1;
+				break;
+
+			/* Modified Julian Day */
+			case 'g':
+				break;
+
+
+			/* Day of Week */
+			case 'E':
+				if (count <= 3) {
+					/* Short */
+					g_string_append(string, purple_utf8_strftime("%a", tm));
+				} else if (count == 4) {
+					/* Full */
+					g_string_append(string, purple_utf8_strftime("%A", tm));
+				} else if (count >= 5) {
+					/* Narrow */
+					g_string_append_len(string, purple_utf8_strftime("%a", tm), 1);
+					count = 5;
+				}
+				break;
+
+			/* Local Day of Week */
+			case 'e':
+				if (count <= 2) {
+					/* Numeric */
+					g_string_append(string, purple_utf8_strftime("%u", tm));
+				} else if (count == 3) {
+					/* Short */
+					g_string_append(string, purple_utf8_strftime("%a", tm));
+				} else if (count == 4) {
+					/* Full */
+					g_string_append(string, purple_utf8_strftime("%A", tm));
+				} else if (count >= 5) {
+					/* Narrow */
+					g_string_append_len(string, purple_utf8_strftime("%a", tm), 1);
+					count = 5;
+				}
+				break;
+
+			/* Stand-alone Local Day of Week */
+			case 'c':
+				if (count <= 2) {
+					/* Numeric */
+					g_string_append(string, purple_utf8_strftime("%u", tm));
+					count = 1;
+				} else if (count == 3) {
+					/* Short */
+					g_string_append(string, purple_utf8_strftime("%a", tm));
+				} else if (count == 4) {
+					/* Full */
+					g_string_append(string, purple_utf8_strftime("%A", tm));
+				} else if (count >= 5) {
+					/* Narrow */
+					g_string_append_len(string, purple_utf8_strftime("%a", tm), 1);
+					count = 5;
+				}
+				break;
+
+
+			/* AM/PM */
+			case 'a':
+				g_string_append(string, purple_utf8_strftime("%p", tm));
+				break;
+
+
+			/* Hour (1-12) */
+			case 'h':
+				if (count == 1) {
+					/* No padding */
+					g_string_append(string, purple_utf8_strftime("%I", tm));
+				} else if (count >= 2) {
+					/* Zero-padded */
+					g_string_append(string, purple_utf8_strftime("%I", tm));
+					count = 2;
+				}
+				break;
+
+			/* Hour (0-23) */
+			case 'H':
+				if (count == 1) {
+					/* No padding */
+					g_string_append(string, purple_utf8_strftime("%H", tm));
+				} else if (count >= 2) {
+					/* Zero-padded */
+					g_string_append(string, purple_utf8_strftime("%H", tm));
+					count = 2;
+				}
+				break;
+
+			/* Hour (0-11) */
+			case 'K':
+				if (count == 1) {
+					/* No padding */
+				} else if (count >= 2) {
+					/* Zero-padded */
+					count = 2;
+				}
+				break;
+
+			/* Hour (1-24) */
+			case 'k':
+				if (count == 1) {
+					/* No padding */
+				} else if (count >= 2) {
+					/* Zero-padded */
+					count = 2;
+				}
+				break;
+
+			/* Hour (hHkK by locale) */
+			case 'j':
+				break;
+
+
+			/* Minute */
+			case 'm':
+				g_string_append(string, purple_utf8_strftime("%M", tm));
+				count = MIN(count, 2);
+				break;
+
+
+			/* Second */
+			case 's':
+				g_string_append(string, purple_utf8_strftime("%S", tm));
+				count = MIN(count, 2);
+				break;
+
+			/* Fractional Sub-second */
+			case 'S':
+				break;
+



More information about the Commits mailing list