@@ -41,7 +41,6 @@ static const int ABBREVIATED_MONTH_NAME_LENGTH = 3;
4141
4242#define f_match (r ,s ) rb_funcall(r, rb_intern("match"), 1, s)
4343#define f_aref (o ,i ) rb_funcall(o, rb_intern("[]"), 1, i)
44- #define f_end (o ,i ) rb_funcall(o, rb_intern("end"), 1, i)
4544
4645#define issign (c ) ((c) == '-' || (c) == '+')
4746
@@ -144,7 +143,7 @@ valid_range_p(VALUE v, int a, int b)
144143do { \
145144 size_t l; \
146145 l = date__strptime_internal(&str[si], slen - si, \
147- fmt, sizeof fmt - 1, hash); \
146+ fmt, sizeof fmt - 1, hash, enc ); \
148147 if (fail_p()) \
149148 return 0; \
150149 si += l; \
@@ -160,7 +159,8 @@ head_match_p(size_t len, const char *name, const char *str, size_t slen, size_t
160159
161160static size_t
162161date__strptime_internal (const char * str , size_t slen ,
163- const char * fmt , size_t flen , VALUE hash )
162+ const char * fmt , size_t flen ,
163+ VALUE hash , rb_encoding * enc )
164164{
165165 size_t si , fi ;
166166 int c ;
@@ -597,15 +597,14 @@ date__strptime_internal(const char *str, size_t slen,
597597
598598 b = rb_backref_get ();
599599 rb_match_busy (b );
600- m = f_match (pat , rb_usascii_str_new (& str [si ], slen - si ));
600+ m = f_match (pat , rb_enc_str_new (& str [si ], slen - si , enc ));
601601
602602 if (!NIL_P (m )) {
603- VALUE s , l , o ;
603+ VALUE s , o ;
604604
605605 s = rb_reg_nth_match (1 , m );
606- l = f_end (m , INT2FIX (0 ));
607606 o = date_zone_to_diff (s );
608- si += NUM2LONG ( l );
607+ si += RSTRING_LEN ( s );
609608 set_hash ("zone" , s );
610609 set_hash ("offset" , o );
611610 rb_backref_set (b );
@@ -654,20 +653,21 @@ date__strptime_internal(const char *str, size_t slen,
654653
655654VALUE
656655date__strptime (const char * str , size_t slen ,
657- const char * fmt , size_t flen , VALUE hash )
656+ const char * fmt , size_t flen ,
657+ VALUE hash , rb_encoding * enc )
658658{
659659 size_t si ;
660660 VALUE cent , merid ;
661661
662- si = date__strptime_internal (str , slen , fmt , flen , hash );
662+ si = date__strptime_internal (str , slen , fmt , flen , hash , enc );
663663
664664 if (fail_p ())
665665 return Qnil ;
666666
667667 if (slen > si ) {
668668 VALUE s ;
669669
670- s = rb_usascii_str_new (& str [si ], slen - si );
670+ s = rb_enc_str_new (& str [si ], slen - si , enc );
671671 set_hash ("leftover" , s );
672672 }
673673
0 commit comments