* lib/date/format.rb (_parse): improved parsing of ordinal dates.

* lib/date/format.rb (_parse): use named character classes in some
	  regular expressions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2007-09-01 15:47:52 +00:00
parent ebef450d28
commit ec6cf1f454
2 changed files with 28 additions and 12 deletions

View File

@ -1,3 +1,10 @@
Sun Sep 2 00:37:57 2007 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date/format.rb (_parse): improved parsing of ordinal dates.
* lib/date/format.rb (_parse): use named character classes in some
regular expressions.
Sat Sep 1 23:44:26 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval_jump.ci (rb_f_throw): wrap tag and TAG_THROW in a NODE_MEMO

View File

@ -1,5 +1,5 @@
# format.rb: Written by Tadayoshi Funaba 1999-2007
# $Id: format.rb,v 2.36 2007-07-21 00:21:04+09 tadf Exp $
# $Id: format.rb,v 2.38 2007-09-01 00:03:46+09 tadf Exp $
require 'rational'
@ -540,8 +540,8 @@ class Date
e._cent ||= if val >= 69 then 19 else 20 end
when 'Z', /\A:{0,3}z/
return unless str.sub!(/\A((?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
|[a-z.\s]+(?:standard|daylight)\s+time\b
|[a-z]+(?:\s+dst)?\b
|[[:alpha:].\s]+(?:standard|daylight)\s+time\b
|[[:alpha:]]+(?:\s+dst)?\b
)/ix, '')
val = $1
e.zone = val
@ -595,6 +595,10 @@ class Date
m = m.to_s
end
if y && m && !d
y, m, d = d, y, m
end
if y == nil
if d && d.size > 2
y = d
@ -690,9 +694,9 @@ class Date
(
(?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
|
[a-z.\s]+(?:standard|daylight)\stime\b
[[:alpha:].\s]+(?:standard|daylight)\stime\b
|
[a-z]+(?:\sdst)?\b
[[:alpha:]]+(?:\sdst)?\b
)
)?
/inx,
@ -803,10 +807,15 @@ class Date
e.mon = $1.to_i
e.mday = $2.to_i if $2
true
elsif str.sub!(/\b(\d{2}|\d{4})?-(\d{3})\b/n, ' ')
e.year = $1.to_i if $1
elsif /[,.](\d{2}|\d{4})-\d{3}\b/n !~ str &&
str.sub!(/\b(\d{2}|\d{4})-(\d{3})\b/n, ' ')
e.year = $1.to_i
e.yday = $2.to_i
true
elsif /\d-\d{3}\b/n !~ str &&
str.sub!(/\b-(\d{3})\b/n, ' ')
e.yday = $1.to_i
true
elsif e._date && str.sub!(/('?[-+]?\d+)-('?-?\d+)/n, ' ')
s3e(e, nil, $1, $2)
true
@ -845,21 +854,21 @@ class Date
end
def self._parse_sla_jp(str, e) # :nodoc:
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
s3e(e, $1, $2, $3)
true
end
end
def self._parse_sla_eu(str, e) # :nodoc:
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
s3e(e, $3, $2, $1)
true
end
end
def self._parse_sla_us(str, e) # :nodoc:
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
s3e(e, $3, $1, $2)
true
end
@ -896,7 +905,7 @@ class Date
end
def self._parse_year(str, e) # :nodoc:
if str.sub!(/'(\d+)\b/in, ' ')
if str.sub!(/'(\d+)\b/n, ' ')
e.year = $1.to_i
true
end
@ -1112,7 +1121,7 @@ class Date
end
end
str.gsub!(/[^-+',.\/:0-9@a-z\[\]\x80-\xff]+/in, ' ')
str.gsub!(/[^-+',.\/:@[:alnum:]\[\]\x80-\xff]+/n, ' ')
case e._style
when :jp