Skip to content

Commit 017149e

Browse files
committed
Separate era from preceding word
1 parent 1fd15f7 commit 017149e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ext/date/date_parse.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ parse_time(VALUE str, VALUE hash)
694694
#endif
695695
}
696696

697+
#define BEGIN_ERA "\\b"
698+
#define END_ERA "(?!(?<!\\.)[a-z])"
699+
697700
#ifdef TIGHT_PARSER
698701
static int
699702
parse_era1_cb(VALUE m, VALUE hash)
@@ -705,7 +708,7 @@ static int
705708
parse_era1(VALUE str, VALUE hash)
706709
{
707710
static const char pat_source[] =
708-
"(a(?:d|\\.d\\.))";
711+
BEGIN_ERA "(a(?:d\\b|\\.d\\.))" END_ERA;
709712
static VALUE pat = Qnil;
710713

711714
REGCOMP_I(pat);
@@ -727,8 +730,9 @@ parse_era2_cb(VALUE m, VALUE hash)
727730
static int
728731
parse_era2(VALUE str, VALUE hash)
729732
{
730-
static const char pat_source[] =
731-
"(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|b(?:c|\\.c\\.))";
733+
static const char pat_source[] = BEGIN_ERA
734+
"(c(?:e\\b|\\.e\\.)|b(?:ce\\b|\\.c\\.e\\.)|b(?:c\\b|\\.c\\.))"
735+
END_ERA;
732736
static VALUE pat = Qnil;
733737

734738
REGCOMP_I(pat);
@@ -845,7 +849,11 @@ parse_eu(VALUE str, VALUE hash)
845849
"(?:"
846850
"\\s*"
847851
#ifndef TIGHT_PARSER
848-
"(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|a(?:d|\\.d\\.)|b(?:c|\\.c\\.))?"
852+
"(?:"
853+
BEGIN_ERA
854+
"(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|a(?:d|\\.d\\.)|b(?:c|\\.c\\.))"
855+
END_ERA
856+
")?"
849857
"\\s*"
850858
"('?-?\\d+(?:(?:st|nd|rd|th)\\b)?)"
851859
#else

0 commit comments

Comments
 (0)