diff --git a/lib/gettext/mo.rb b/lib/gettext/mo.rb index a422c657..44e8fc5f 100644 --- a/lib/gettext/mo.rb +++ b/lib/gettext/mo.rb @@ -43,8 +43,8 @@ class HeaderRev1 < Header :trans_sysdep_tab_offset end - MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde".force_encoding("ASCII-8BIT") - MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95".force_encoding("ASCII-8BIT") + MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde".dup.force_encoding("ASCII-8BIT") + MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95".dup.force_encoding("ASCII-8BIT") def self.open(arg = nil, output_charset = nil) result = self.new(output_charset) @@ -325,7 +325,7 @@ def convert_encoding(string, original_string) end def generate_original_string(msgid, options) - string = "" + string = "".dup msgctxt = options.delete(:msgctxt) msgid_plural = options.delete(:msgid_plural) diff --git a/lib/gettext/po.rb b/lib/gettext/po.rb index c78f084a..54d87b74 100644 --- a/lib/gettext/po.rb +++ b/lib/gettext/po.rb @@ -194,7 +194,7 @@ def set_comment(msgid, comment, msgctxt=nil) # @return [String] Formatted and joined PO entries. It is used for # creating .po files. def to_s(options={}) - po_string = "" + po_string = "".dup header_entry = @entries[[nil, ""]] unless header_entry.nil? diff --git a/lib/gettext/po_entry.rb b/lib/gettext/po_entry.rb index f0f6ff84..30d4eeb3 100644 --- a/lib/gettext/po_entry.rb +++ b/lib/gettext/po_entry.rb @@ -83,7 +83,7 @@ def initialize(type) # @return [void] def add_comment(new_comment) if (new_comment and ! new_comment.empty?) - @extracted_comment ||= "" + @extracted_comment ||= "".dup @extracted_comment << "\n" unless @extracted_comment.empty? @extracted_comment << new_comment end @@ -366,7 +366,7 @@ def include_previous_comment? end def format_comments - formatted_comment = "" + formatted_comment = "".dup if include_translator_comment? formatted_comment << format_translator_comment end @@ -395,7 +395,7 @@ def format_extracted_comment def format_reference_comment max_line_width = @options[:max_line_width] - formatted_reference = "" + formatted_reference = "".dup if not @entry.references.nil? and not @entry.references.empty? formatted_reference << REFERENCE_COMMENT_MARK line_width = 2 @@ -417,7 +417,7 @@ def format_reference_comment end def format_flag_comment - formatted_flags = "" + formatted_flags = "".dup @entry.flags.each do |flag| formatted_flags << format_comment(FLAG_MARK, flag) end @@ -431,7 +431,7 @@ def format_previous_comment def format_comment(mark, comment) return "" if comment.nil? - formatted_comment = "" + formatted_comment = "".dup comment.each_line do |comment_line| if comment_line == "\n" formatted_comment << "#{mark}\n" @@ -446,7 +446,7 @@ def format_obsolete_comment(comment) mark = "#~" return "" if comment.nil? - formatted_comment = "" + formatted_comment = "".dup comment.each_line do |comment_line| if /\A#[^~]/ =~ comment_line or comment_line.start_with?(mark) formatted_comment << "#{comment_line.chomp}\n" @@ -466,7 +466,7 @@ def format_message(message) chunks = wrap_message(message) return empty_formatted_message if chunks.empty? - formatted_message = "" + formatted_message = "".dup if chunks.size > 1 or chunks.first.end_with?("\n") formatted_message << empty_formatted_message end diff --git a/lib/gettext/tools/msgcat.rb b/lib/gettext/tools/msgcat.rb index d61a83d4..bbde7e1d 100644 --- a/lib/gettext/tools/msgcat.rb +++ b/lib/gettext/tools/msgcat.rb @@ -121,7 +121,7 @@ def remove_header_fields!(header_entry) msgstr = header_entry.msgstr return if msgstr.nil? - new_msgstr = "" + new_msgstr = "".dup msgstr.each_line do |line| case line when /\A([\w\-]+):/ diff --git a/lib/gettext/tools/parser/ruby.rb b/lib/gettext/tools/parser/ruby.rb index 2886b779..20a58fc8 100644 --- a/lib/gettext/tools/parser/ruby.rb +++ b/lib/gettext/tools/parser/ruby.rb @@ -236,7 +236,7 @@ def parse_source(source) po_entry = nil line_no = nil - last_comment = "" + last_comment = "".dup reset_comment = false ignore_next_comma = false rl.parse do |tk| @@ -287,7 +287,7 @@ def parse_source(source) case tk when RubyToken::TkCOMMENT_WITH_CONTENT - last_comment = "" if reset_comment + last_comment = "".dup if reset_comment if last_comment.empty? comment1 = tk.value.lstrip if comment_to_be_extracted?(comment1) diff --git a/test/test_po.rb b/test/test_po.rb index bf0e8a51..0f224141 100644 --- a/test/test_po.rb +++ b/test/test_po.rb @@ -208,7 +208,7 @@ class TestOrder < self def setup @po = GetText::PO.new parser = GetText::POParser.new - parser.parse(<<-PO, @po) + parser.parse(<<-PO.dup, @po) #: hello.rb:2 msgid "World" msgstr "" @@ -300,7 +300,7 @@ def setup class TestHeader < self def test_no_entry - @po[""] = <<-HEADER + @po[""] = <<-HEADER.dup Project-Id-Version: test 1.0.0 POT-Creation-Date: 2012-10-31 12:40+0900 PO-Revision-Date: 2012-11-01 17:46+0900 @@ -312,7 +312,7 @@ def test_no_entry Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n != 1) HEADER - @po[""].translator_comment = <<-HEADER_COMMENT + @po[""].translator_comment = <<-HEADER_COMMENT.dup Japanese translations for test package. Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER This file is distributed under the same license as the PACKAGE package. diff --git a/test/tools/test_msginit.rb b/test/tools/test_msginit.rb index 82d6e96a..b2fc5956 100644 --- a/test/tools/test_msginit.rb +++ b/test/tools/test_msginit.rb @@ -81,7 +81,7 @@ def pot_header(options) options = default_po_header_options.merge(options) package_name = options[:package_name] || default_package_name have_plural_forms = options[:have_plural_forms] || true - header = <