aboutsummaryrefslogtreecommitdiff
path: root/mod/types-parsers.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'mod/types-parsers.cxx')
-rw-r--r--mod/types-parsers.cxx42
1 files changed, 39 insertions, 3 deletions
diff --git a/mod/types-parsers.cxx b/mod/types-parsers.cxx
index dc21e97..422b353 100644
--- a/mod/types-parsers.cxx
+++ b/mod/types-parsers.cxx
@@ -3,11 +3,15 @@
#include <mod/types-parsers.hxx>
+#include <sstream>
+
+#include <libbutl/regex.mxx>
#include <libbutl/timestamp.mxx> // from_string()
#include <mod/module-options.hxx>
using namespace std;
+using namespace butl;
using namespace bpkg;
using namespace web::xhtml;
@@ -75,9 +79,9 @@ namespace brep
string t ("1970-01-01 ");
t += v;
- x = butl::from_string (t.c_str (),
- "%Y-%m-%d %H:%M",
- false /* local */).time_since_epoch ();
+ x = from_string (t.c_str (),
+ "%Y-%m-%d %H:%M",
+ false /* local */).time_since_epoch ();
return;
}
catch (const invalid_argument&) {}
@@ -181,5 +185,37 @@ namespace brep
throw invalid_value (o, v);
}
}
+
+ // Parse the '/regex/replacement/' string into the regex/replacement pair.
+ //
+ void parser<pair<std::regex, string>>::
+ parse (pair<std::regex, string>& x, bool& xs, scanner& s)
+ {
+ xs = true;
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ const char* v (s.next ());
+
+ try
+ {
+ x = regex_replace_parse (v);
+ }
+ catch (const invalid_argument& e)
+ {
+ throw invalid_value (o, v, e.what ());
+ }
+ catch (const regex_error& e)
+ {
+ // Sanitize the description.
+ //
+ ostringstream os;
+ os << e;
+
+ throw invalid_value (o, v, os.str ());
+ }
+ }
}
}