pidgin/pidgin

Merged in default (pull request #630)

15 months ago, Gary Kramlich
e374a2cf0611
Merged in default (pull request #630)

Add purple_get_month() util function

Approved-by: Elliott Sales de Andrade
Approved-by: Gary Kramlich
Approved-by: Eion Robb
--- a/ChangeLog.API Mon Nov 11 02:47:44 2019 +0000
+++ b/ChangeLog.API Mon Nov 11 03:41:58 2019 +0000
@@ -124,6 +124,7 @@
* purple_roomlist_room_set_expanded_once
* purple_roomlist_set_proto_data
* purple_roomlist_set_ui_data
+ * purple_time_parse_month
* purple_whiteboard_get_account
* purple_whiteboard_get_draw_list
* purple_whiteboard_set_draw_list
--- a/libpurple/log.c Mon Nov 11 02:47:44 2019 +0000
+++ b/libpurple/log.c Mon Nov 11 03:41:58 2019 +0000
@@ -1704,31 +1704,7 @@
purple_debug_warning("log", "invalid date format\n");
}
/* Ugly hack, in case current locale is not English */
- if (purple_strequal(month_str, "Jan")) {
- month = 1;
- } else if (purple_strequal(month_str, "Feb")) {
- month = 2;
- } else if (purple_strequal(month_str, "Mar")) {
- month = 3;
- } else if (purple_strequal(month_str, "Apr")) {
- month = 4;
- } else if (purple_strequal(month_str, "May")) {
- month = 5;
- } else if (purple_strequal(month_str, "Jun")) {
- month = 6;
- } else if (purple_strequal(month_str, "Jul")) {
- month = 7;
- } else if (purple_strequal(month_str, "Aug")) {
- month = 8;
- } else if (purple_strequal(month_str, "Sep")) {
- month = 9;
- } else if (purple_strequal(month_str, "Oct")) {
- month = 10;
- } else if (purple_strequal(month_str, "Nov")) {
- month = 11;
- } else if (purple_strequal(month_str, "Dec")) {
- month = 12;
- }
+ month = purple_time_parse_month(month_str);
if (lasttime)
g_date_time_unref(lasttime);
lasttime = g_date_time_new_local(year, month, day,
--- a/libpurple/plugins/log_reader.c Mon Nov 11 02:47:44 2019 +0000
+++ b/libpurple/plugins/log_reader.c Mon Nov 11 03:41:58 2019 +0000
@@ -32,19 +32,6 @@
NAME_GUESS_THEM
};
-/* Some common functions. */
-static int get_month(const char *month)
-{
- int iter;
- const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
- for (iter = 0; months[iter]; iter++) {
- if (purple_strequal(month, months[iter]))
- break;
- }
- return iter;
-}
-
/*****************************************************************************
* Adium Logger *
@@ -1222,7 +1209,7 @@
} else {
PurpleLog *log;
- month = get_month(month_str);
+ month = purple_time_parse_month(month_str);
data = g_new0(
struct trillian_logger_data, 1);
@@ -2026,7 +2013,7 @@
"Error parsing start date for %s\n",
filename);
} else {
- month = get_month(month_str);
+ month = purple_time_parse_month(month_str);
found_start = TRUE;
offset = c - contents;
--- a/libpurple/util.c Mon Nov 11 02:47:44 2019 +0000
+++ b/libpurple/util.c Mon Nov 11 03:41:58 2019 +0000
@@ -561,6 +561,20 @@
return retval;
}
+gint purple_time_parse_month(const char *month_abbr)
+{
+ const char *months[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
+ NULL};
+ for (gint month = 0; months[month] != NULL; month++) {
+ if (purple_strequal(month_abbr, months[month])) {
+ return month + 1;
+ }
+ }
+ return 0;
+}
+
/**************************************************************************
* Markup Functions
**************************************************************************/
--- a/libpurple/util.h Mon Nov 11 02:47:44 2019 +0000
+++ b/libpurple/util.h Mon Nov 11 03:41:58 2019 +0000
@@ -314,6 +314,19 @@
*/
GDateTime *purple_str_to_date_time(const char *timestamp, gboolean utc);
+/**
+ * purple_time_parse_month:
+ * @month_abbr: The 3-letter month abbreviation
+ *
+ * Get month number suitable for GDateTime. If @month_abbr is unknown,
+ * returns 0.
+ *
+ * Returns: A month number or 0.
+ *
+ * Since: 3.0.0
+ */
+gint purple_time_parse_month(const char *month_abbr);
+
/**************************************************************************/
/* Markup Functions */
/**************************************************************************/