From 7b502c8af7d07286bcb8df20060df8bc73281794 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 19 Apr 2020 21:44:39 -0400 Subject: cgi search form, no date_published breaks regex, initialize to "0000" --- org/out_cgi_search_sqlite.org | 15 ++++++++------- src/doc_reform/io_out/cgi_sqlite_search_form.d | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/org/out_cgi_search_sqlite.org b/org/out_cgi_search_sqlite.org index 4f3ccad..62f456d 100644 --- a/org/out_cgi_search_sqlite.org +++ b/org/out_cgi_search_sqlite.org @@ -1723,10 +1723,14 @@ LIMIT %%s OFFSET %%s auto select_query_results = db.execute(sql_select.the_body).cached; string _old_uid = ""; if (!select_query_results.empty) { + string _date_published = "0000"; foreach (row; select_query_results) { if (row["uid"].as!string != _old_uid) { _old_uid = row["uid"].as!string; - auto m = (row["date_published"].as!string).match(regex(r"^([0-9]{4})")); // breaks if row missing or no match? + _date_published = (row["date_published"].as!string.match(regex(r"^([0-9]{4})"))) + ? row["date_published"].as!string : "0000"; // used in regex that breaks if no match + auto m = _date_published.match(regex(r"^([0-9]{4})")); + string _date = (m.hit == "0000") ? "(year?) " : "(" ~ m.hit ~ ") "; cgi.write( "
\"" ~ row["title"].as!string ~ "\"" - ~ " (" - ~ m.hit - ~ ") " - ~ "[" - ~ row["language_document_char"].as!string - ~ "] " + ~ " " + ~ _date + ~ "[" ~ row["language_document_char"].as!string ~ "] " ~ row["creator_author_last_first"].as!string ~ " " ~ show_matched_objects(row["src_filename_base"].as!string) diff --git a/src/doc_reform/io_out/cgi_sqlite_search_form.d b/src/doc_reform/io_out/cgi_sqlite_search_form.d index 145203f..4a77d48 100644 --- a/src/doc_reform/io_out/cgi_sqlite_search_form.d +++ b/src/doc_reform/io_out/cgi_sqlite_search_form.d @@ -1348,10 +1348,14 @@ LIMIT %%s OFFSET %%s auto select_query_results = db.execute(sql_select.the_body).cached; string _old_uid = ""; if (!select_query_results.empty) { + string _date_published = "0000"; foreach (row; select_query_results) { if (row["uid"].as!string != _old_uid) { _old_uid = row["uid"].as!string; - auto m = (row["date_published"].as!string).match(regex(r"^([0-9]{4})")); // breaks if row missing or no match? + _date_published = (row["date_published"].as!string.match(regex(r"^([0-9]{4})"))) + ? row["date_published"].as!string : "0000"; // used in regex that breaks if no match + auto m = _date_published.match(regex(r"^([0-9]{4})")); + string _date = (m.hit == "0000") ? "(year?) " : "(" ~ m.hit ~ ") "; cgi.write( "
\"" ~ row["title"].as!string ~ "\"" - ~ " (" - ~ m.hit - ~ ") " - ~ "[" - ~ row["language_document_char"].as!string - ~ "] " + ~ " " + ~ _date + ~ "[" ~ row["language_document_char"].as!string ~ "] " ~ row["creator_author_last_first"].as!string ~ " " ~ show_matched_objects(row["src_filename_base"].as!string) -- cgit v1.2.3