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
|
.index_minute = 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.regex = "(\\d{2,2})\\.(\\d{1,2})\\.(\\d{1,4})\\s*(\\d{1,2}):(\\d{1,2}).*",
|
.regex = "(\\d{1,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... */
|
|
||||||
.index_count = 5,
|
.index_count = 5,
|
||||||
.index_year = 3,
|
.index_year = 3,
|
||||||
.index_month = 2,
|
.index_month = 2,
|
||||||
@ -80,7 +79,7 @@ GDateTime *mdiary_get_date_from_string_ext(gchar *string, gchar *prefix, gchar *
|
|||||||
|
|
||||||
dateFormats = dateFormats_list;
|
dateFormats = dateFormats_list;
|
||||||
do {
|
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);
|
regex = g_regex_new(regex_string, G_REGEX_RAW, 0, NULL);
|
||||||
if (g_regex_match(regex, string, 0, &match_info)
|
if (g_regex_match(regex, string, 0, &match_info)
|
||||||
&& g_regex_get_capture_count(regex) >= dateFormats->index_count &&
|
&& 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))) {
|
g_data_input_stream_read_line(G_DATA_INPUT_STREAM(dstream), NULL, NULL, NULL))) {
|
||||||
if (header_state == 0) {
|
if (header_state == 0) {
|
||||||
if (!datetime) {
|
if (!datetime) {
|
||||||
datetime = mdiary_get_date_from_string_ext(line, "Date: .*", "");
|
datetime = mdiary_get_date_from_string_ext(line, "Date: ", "");
|
||||||
if (datetime)
|
if (datetime)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user