diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-03-02 16:21:11 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-03-02 16:21:11 +0000 |
commit | 40daca4a87d4e7177a1fce943f09b793582bb50d (patch) | |
tree | dfa58e8bb6a8de56630722c4924bcbb761d71788 | |
parent | a5e13ce5ffbf6febf65b74de3358e9b2f73a4e6b (diff) | |
download | ruby-40daca4a87d4e7177a1fce943f09b793582bb50d.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/rss/1.0.rb | 16 | ||||
-rw-r--r-- | lib/rss/converter.rb | 48 | ||||
-rw-r--r-- | lib/rss/dublincore.rb | 17 |
4 files changed, 42 insertions, 45 deletions
@@ -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> * scanf.rb: soak_up_spaces only ungetc's non-space last diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb index d3c337eecd..cd645eedb3 100644 --- a/lib/rss/1.0.rb +++ b/lib/rss/1.0.rb @@ -75,11 +75,11 @@ EORDF private def xmldecl - rv = "<?xml version='#{@version}'" + rv = %Q[<?xml version="#{@version}"] if @output_encoding or @encoding - rv << " encoding='#{@output_encoding or @encoding}'" + rv << %Q[ encoding="#{@output_encoding or @encoding}"] end - rv << " standalone='#{@standalone}'" if @standalone + rv << %Q[ standalone="#{@standalone}"] if @standalone rv << '?>' rv end @@ -138,10 +138,10 @@ EORDF def to_s(convert=true) <<-EOT - <#{PREFIX}:Seq> -#{li_elements(convert, "\t\t\t\t\t")} -#{other_element(convert, "\t\t\t\t\t")} - </#{PREFIX}:Seq> + <#{PREFIX}:Seq> +#{li_elements(convert, "\t\t\t\t")} +#{other_element(convert, "\t\t\t\t")} + </#{PREFIX}:Seq> EOT end @@ -189,7 +189,7 @@ EOT def to_s(convert=true) 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 else diff --git a/lib/rss/converter.rb b/lib/rss/converter.rb index 4f00c86973..5037606f37 100644 --- a/lib/rss/converter.rb +++ b/lib/rss/converter.rb @@ -47,9 +47,8 @@ module RSS @iconv.iconv(#{value}) rescue Iconv::Failure raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}") - #{value} end -EOC + EOC end rescue LoadError, ArgumentError, SystemCallError raise UnknownConversionMethodError.new(to_enc, from_enc) @@ -66,48 +65,37 @@ EOC end end - def def_to_euc_jp_from_utf_8 + def def_uconv_convert_if_can(meth, to_enc, from_enc) begin require "uconv" 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 rescue LoadError - def_iconv_convert('EUC-JP', 'UTF-8') + def_iconv_convert(to_enc, from_enc) 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 - begin - require "uconv" - def_convert do |value| - "Uconv.euctou8(#{value})" - end - rescue LoadError - def_iconv_convert('UTF-8', 'EUC-JP') - end + def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP') end def def_to_shift_jis_from_utf_8 - begin - require "uconv" - def_convert do |value| - "Uconv.u8tosjis(#{value})" - end - rescue LoadError - def_iconv_convert('Shift_JIS', 'UTF-8') - end + def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8') end def def_to_utf_8_from_shift_jis - begin - require "uconv" - def_convert do |value| - "Uconv.sjistou8(#{value})" - end - rescue LoadError - def_iconv_convert('UTF-8', 'Shift_JIS') - end + def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS') end def def_to_euc_jp_from_shift_jis @@ -157,7 +145,7 @@ EOC end end array_enc.pack('C*') -EOC + EOC end end diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb index 18b5413a5c..4b5daf5076 100644 --- a/lib/rss/dublincore.rb +++ b/lib/rss/dublincore.rb @@ -7,7 +7,7 @@ module RSS RDF.install_ns(DC_PREFIX, DC_URI) - module DublincoreModel + module DublinCoreModel extend BaseModel @@ -43,16 +43,19 @@ module RSS end + # For backward compatibility + DublincoreModel = DublinCoreModel + class RDF - class Channel; include DublincoreModel; end - class Image; include DublincoreModel; end - class Item; include DublincoreModel; end - class Textinput; include DublincoreModel; end + class Channel; include DublinCoreModel; end + class Image; include DublinCoreModel; end + class Item; include DublinCoreModel; end + class Textinput; include DublinCoreModel; end end prefix_size = DC_PREFIX.size + 1 - DublincoreModel::ELEMENTS.uniq! - DublincoreModel::ELEMENTS.each do |x| + DublinCoreModel::ELEMENTS.uniq! + DublinCoreModel::ELEMENTS.each do |x| BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=") end |