Regex cleanups and fixes

This commit is contained in:
Markus Koch 2017-02-02 21:56:07 +01:00
parent 8ac7436182
commit ba24dc9e9b

View File

@ -22,7 +22,7 @@ struct dateFormats {
guint index_minute; guint index_minute;
} dateFormats_list[] = { } dateFormats_list[] = {
{ {
.regex = "(\\d{1,4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{1,2}).*", .regex = "(\\d{1,4})-(\\d{1,2})-(\\d{1,2})\\s*(\\d{1,2}):(\\d{1,2}).*",
.index_count = 5, .index_count = 5,
.index_year = 1, .index_year = 1,
.index_month = 2, .index_month = 2,
@ -30,6 +30,15 @@ struct dateFormats {
.index_hour = 4, .index_hour = 4,
.index_minute = 5 .index_minute = 5
}, },
{
.regex = "(\\d{1,2})\\.(\\d{1,2})\\.(\\d{1,4})\\s*(\\d{1,2}):(\\d{1,2}).*",
.index_count = 5,
.index_year = 3,
.index_month = 2,
.index_day = 1,
.index_hour = 4,
.index_minute = 5
},
{ {
.regex = "(\\d{1,4})-(\\d{1,2})-(\\d{1,2}).*", .regex = "(\\d{1,4})-(\\d{1,2})-(\\d{1,2}).*",
.index_count = 3, .index_count = 3,
@ -89,7 +98,7 @@ static GDateTime *mainWindow_get_date_from_string(gchar *string)
day >= 1 && day <= 31 && day >= 1 && day <= 31 &&
hour >= 0 && hour <= 23 && hour >= 0 && hour <= 23 &&
minute >= 0 && minute <= 59) { minute >= 0 && minute <= 59) {
datetime = g_date_time_new_local(year, month, day, 0, 0, 0); datetime = g_date_time_new_local(year, month, day, hour, minute, 0);
g_regex_unref(regex); g_regex_unref(regex);
break; break;
@ -99,7 +108,7 @@ static GDateTime *mainWindow_get_date_from_string(gchar *string)
} while ((++dateFormats)->regex); } while ((++dateFormats)->regex);
if (!datetime) if (!datetime)
g_print("Warning! Could not match date \"%s\"!\n", string); g_print("Warning! Could not match date in \"%s\"!\n", string);
return datetime; return datetime;
} }
@ -334,9 +343,6 @@ struct mainWindow *mainWindow_new()
mainWindow_configure_treeView(mainWindow); mainWindow_configure_treeView(mainWindow);
mainWindow_connect_signals(mainWindow); mainWindow_connect_signals(mainWindow);
mainWindow_get_date_from_string("pointless foo");
mainWindow_get_date_from_string("2017-02-11 12:44");
return mainWindow; return mainWindow;
} }