Added fix for weird behavior of GRegex
This commit is contained in:
parent
a2a8357e6c
commit
4245310392
@ -22,8 +22,7 @@ struct dateFormats {
|
||||
.index_minute = 5
|
||||
},
|
||||
{
|
||||
.regex = "(\\d{2,2})\\.(\\d{1,2})\\.(\\d{1,4})\\s*(\\d{1,2}):(\\d{1,2}).*",
|
||||
/* The regex above should begin with (\d{1,2}). But that seems to break the regex... */
|
||||
.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,
|
||||
@ -80,7 +79,7 @@ GDateTime *mdiary_get_date_from_string_ext(gchar *string, gchar *prefix, gchar *
|
||||
|
||||
dateFormats = dateFormats_list;
|
||||
do {
|
||||
regex_string = g_strdup_printf("%s%s%s", prefix, dateFormats->regex, suffix);
|
||||
regex_string = g_strdup_printf("^\\s*%s%s%s", prefix, dateFormats->regex, suffix);
|
||||
regex = g_regex_new(regex_string, G_REGEX_RAW, 0, NULL);
|
||||
if (g_regex_match(regex, string, 0, &match_info)
|
||||
&& g_regex_get_capture_count(regex) >= dateFormats->index_count &&
|
||||
@ -284,7 +283,7 @@ static void mdiary_add_file_to_store(struct mdiary_scanner *mdiary_scanner,
|
||||
g_data_input_stream_read_line(G_DATA_INPUT_STREAM(dstream), NULL, NULL, NULL))) {
|
||||
if (header_state == 0) {
|
||||
if (!datetime) {
|
||||
datetime = mdiary_get_date_from_string_ext(line, "Date: .*", "");
|
||||
datetime = mdiary_get_date_from_string_ext(line, "Date: ", "");
|
||||
if (datetime)
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user