summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-07-09 06:41:29 +0900
committergit <svn-admin@ruby-lang.org>2022-02-25 19:52:30 +0900
commitd54a3df2e53a964c8bb36b87bc10ba2512830a60 (patch)
treea16baef051f329ce2917197f6f425bda383441d4 /ext/date
parentc8cddac45c3786afc737ac9c1075d77d8f752d3d (diff)
[ruby/date] Separate era from preceding word
https://github.com/ruby/date/commit/017149e53e
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/date_parse.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 0e7067f4d8..021df3793b 100644
--- a/ext/date/date_parse.c
+++ b/ext/date/date_parse.c
@@ -694,6 +694,9 @@ parse_time(VALUE str, VALUE hash)
#endif
}
+#define BEGIN_ERA "\\b"
+#define END_ERA "(?!(?<!\\.)[a-z])"
+
#ifdef TIGHT_PARSER
static int
parse_era1_cb(VALUE m, VALUE hash)
@@ -705,7 +708,7 @@ static int
parse_era1(VALUE str, VALUE hash)
{
static const char pat_source[] =
- "(a(?:d|\\.d\\.))";
+ BEGIN_ERA "(a(?:d\\b|\\.d\\.))" END_ERA;
static VALUE pat = Qnil;
REGCOMP_I(pat);
@@ -727,8 +730,9 @@ parse_era2_cb(VALUE m, VALUE hash)
static int
parse_era2(VALUE str, VALUE hash)
{
- static const char pat_source[] =
- "(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|b(?:c|\\.c\\.))";
+ static const char pat_source[] = BEGIN_ERA
+ "(c(?:e\\b|\\.e\\.)|b(?:ce\\b|\\.c\\.e\\.)|b(?:c\\b|\\.c\\.))"
+ END_ERA;
static VALUE pat = Qnil;
REGCOMP_I(pat);
@@ -845,7 +849,11 @@ parse_eu(VALUE str, VALUE hash)
"(?:"
"\\s*"
#ifndef TIGHT_PARSER
- "(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|a(?:d|\\.d\\.)|b(?:c|\\.c\\.))?"
+ "(?:"
+ BEGIN_ERA
+ "(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|a(?:d|\\.d\\.)|b(?:c|\\.c\\.))"
+ END_ERA
+ ")?"
"\\s*"
"('?-?\\d+(?:(?:st|nd|rd|th)\\b)?)"
#else