* lib/rss/converter.rb: handled Uconv::Error.
* lib/rss/dublincore.rb: DublincoreModel -> DublinCoreModel git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a5e13ce5ff
commit
40daca4a87
@ -1,3 +1,9 @@
|
|||||||
|
Wed Mar 3 01:18:52 2004 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
|
* lib/rss/converter.rb: handled Uconv::Error.
|
||||||
|
|
||||||
|
* lib/rss/dublincore.rb: DublincoreModel -> DublinCoreModel
|
||||||
|
|
||||||
Wed Mar 3 00:59:30 2004 David Black <dblack@wobblini.net>
|
Wed Mar 3 00:59:30 2004 David Black <dblack@wobblini.net>
|
||||||
|
|
||||||
* scanf.rb: soak_up_spaces only ungetc's non-space last
|
* scanf.rb: soak_up_spaces only ungetc's non-space last
|
||||||
|
@ -75,11 +75,11 @@ EORDF
|
|||||||
|
|
||||||
private
|
private
|
||||||
def xmldecl
|
def xmldecl
|
||||||
rv = "<?xml version='#{@version}'"
|
rv = %Q[<?xml version="#{@version}"]
|
||||||
if @output_encoding or @encoding
|
if @output_encoding or @encoding
|
||||||
rv << " encoding='#{@output_encoding or @encoding}'"
|
rv << %Q[ encoding="#{@output_encoding or @encoding}"]
|
||||||
end
|
end
|
||||||
rv << " standalone='#{@standalone}'" if @standalone
|
rv << %Q[ standalone="#{@standalone}"] if @standalone
|
||||||
rv << '?>'
|
rv << '?>'
|
||||||
rv
|
rv
|
||||||
end
|
end
|
||||||
@ -138,10 +138,10 @@ EORDF
|
|||||||
|
|
||||||
def to_s(convert=true)
|
def to_s(convert=true)
|
||||||
<<-EOT
|
<<-EOT
|
||||||
<#{PREFIX}:Seq>
|
<#{PREFIX}:Seq>
|
||||||
#{li_elements(convert, "\t\t\t\t\t")}
|
#{li_elements(convert, "\t\t\t\t")}
|
||||||
#{other_element(convert, "\t\t\t\t\t")}
|
#{other_element(convert, "\t\t\t\t")}
|
||||||
</#{PREFIX}:Seq>
|
</#{PREFIX}:Seq>
|
||||||
EOT
|
EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ EOT
|
|||||||
|
|
||||||
def to_s(convert=true)
|
def to_s(convert=true)
|
||||||
if @resource
|
if @resource
|
||||||
rv = %Q!<#{PREFIX}:li resource="#{h @resource}" />!
|
rv = %Q!<#{PREFIX}:li resource="#{h @resource}" />\n!
|
||||||
rv = @converter.convert(rv) if convert and @converter
|
rv = @converter.convert(rv) if convert and @converter
|
||||||
rv
|
rv
|
||||||
else
|
else
|
||||||
|
@ -47,9 +47,8 @@ module RSS
|
|||||||
@iconv.iconv(#{value})
|
@iconv.iconv(#{value})
|
||||||
rescue Iconv::Failure
|
rescue Iconv::Failure
|
||||||
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
|
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
|
||||||
#{value}
|
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
rescue LoadError, ArgumentError, SystemCallError
|
rescue LoadError, ArgumentError, SystemCallError
|
||||||
raise UnknownConversionMethodError.new(to_enc, from_enc)
|
raise UnknownConversionMethodError.new(to_enc, from_enc)
|
||||||
@ -66,48 +65,37 @@ EOC
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def def_to_euc_jp_from_utf_8
|
def def_uconv_convert_if_can(meth, to_enc, from_enc)
|
||||||
begin
|
begin
|
||||||
require "uconv"
|
require "uconv"
|
||||||
def_convert do |value|
|
def_convert do |value|
|
||||||
"Uconv.u8toeuc(#{value})"
|
<<-EOC
|
||||||
|
begin
|
||||||
|
Uconv.#{meth}(#{value})
|
||||||
|
rescue Uconv::Error
|
||||||
|
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
|
||||||
|
end
|
||||||
|
EOC
|
||||||
end
|
end
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
def_iconv_convert('EUC-JP', 'UTF-8')
|
def_iconv_convert(to_enc, from_enc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def def_to_euc_jp_from_utf_8
|
||||||
|
def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8')
|
||||||
|
end
|
||||||
|
|
||||||
def def_to_utf_8_from_euc_jp
|
def def_to_utf_8_from_euc_jp
|
||||||
begin
|
def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP')
|
||||||
require "uconv"
|
|
||||||
def_convert do |value|
|
|
||||||
"Uconv.euctou8(#{value})"
|
|
||||||
end
|
|
||||||
rescue LoadError
|
|
||||||
def_iconv_convert('UTF-8', 'EUC-JP')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def def_to_shift_jis_from_utf_8
|
def def_to_shift_jis_from_utf_8
|
||||||
begin
|
def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8')
|
||||||
require "uconv"
|
|
||||||
def_convert do |value|
|
|
||||||
"Uconv.u8tosjis(#{value})"
|
|
||||||
end
|
|
||||||
rescue LoadError
|
|
||||||
def_iconv_convert('Shift_JIS', 'UTF-8')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def def_to_utf_8_from_shift_jis
|
def def_to_utf_8_from_shift_jis
|
||||||
begin
|
def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS')
|
||||||
require "uconv"
|
|
||||||
def_convert do |value|
|
|
||||||
"Uconv.sjistou8(#{value})"
|
|
||||||
end
|
|
||||||
rescue LoadError
|
|
||||||
def_iconv_convert('UTF-8', 'Shift_JIS')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def def_to_euc_jp_from_shift_jis
|
def def_to_euc_jp_from_shift_jis
|
||||||
@ -157,7 +145,7 @@ EOC
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
array_enc.pack('C*')
|
array_enc.pack('C*')
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ module RSS
|
|||||||
|
|
||||||
RDF.install_ns(DC_PREFIX, DC_URI)
|
RDF.install_ns(DC_PREFIX, DC_URI)
|
||||||
|
|
||||||
module DublincoreModel
|
module DublinCoreModel
|
||||||
|
|
||||||
extend BaseModel
|
extend BaseModel
|
||||||
|
|
||||||
@ -43,16 +43,19 @@ module RSS
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For backward compatibility
|
||||||
|
DublincoreModel = DublinCoreModel
|
||||||
|
|
||||||
class RDF
|
class RDF
|
||||||
class Channel; include DublincoreModel; end
|
class Channel; include DublinCoreModel; end
|
||||||
class Image; include DublincoreModel; end
|
class Image; include DublinCoreModel; end
|
||||||
class Item; include DublincoreModel; end
|
class Item; include DublinCoreModel; end
|
||||||
class Textinput; include DublincoreModel; end
|
class Textinput; include DublinCoreModel; end
|
||||||
end
|
end
|
||||||
|
|
||||||
prefix_size = DC_PREFIX.size + 1
|
prefix_size = DC_PREFIX.size + 1
|
||||||
DublincoreModel::ELEMENTS.uniq!
|
DublinCoreModel::ELEMENTS.uniq!
|
||||||
DublincoreModel::ELEMENTS.each do |x|
|
DublinCoreModel::ELEMENTS.each do |x|
|
||||||
BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=")
|
BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user