src/po_parser.ry in gettext-3.4.5 vs src/po_parser.ry in gettext-3.4.6

- old
+ new

@@ -22,11 +22,11 @@ ; msgctxt : MSGCTXT string_list { - @msgctxt = unescape(val[1]) + @msgctxt = val[1] } ; message : single_message @@ -34,23 +34,22 @@ ; single_message : MSGID string_list MSGSTR string_list { - msgid_raw = val[1] - msgid = unescape(msgid_raw) - msgstr = unescape(val[3]) + msgid = val[1] + msgstr = val[3] use_message_p = true if @fuzzy and not msgid.empty? use_message_p = (not ignore_fuzzy?) if report_warning? if ignore_fuzzy? $stderr.print _("Warning: fuzzy message was ignored.\n") else $stderr.print _("Warning: fuzzy message was used.\n") end - $stderr.print " #{@po_file}: msgid '#{msgid_raw}'\n" + $stderr.print " #{@po_file}: msgid '#{msgid}'\n" end end @fuzzy = false on_message(msgid, msgstr) if use_message_p result = "" @@ -142,24 +141,27 @@ def report_warning? @report_warning end - def unescape(orig) - ret = orig.gsub(/\\n/, "\n") - ret.gsub!(/\\t/, "\t") - ret.gsub!(/\\r/, "\r") - ret.gsub!(/\\"/, "\"") - ret + def unescape(string) + string.gsub(/\\(.)/) do + escaped_character = $1 + case escaped_character + when "t" + "\t" + when "r" + "\r" + when "n" + "\n" + else + escaped_character + end + end end private :unescape - def unescape_string(string) - string.gsub(/\\\\/, "\\") - end - private :unescape_string - def parse(str, data) @translator_comments = [] @extracted_comments = [] @references = [] @flags = [] @@ -200,10 +202,10 @@ str = $' when /\A\#(.*)/ @q.push [:COMMENT, $&] str = $' when /\A\"(.*)\"/ - @q.push [:STRING, unescape_string($1)] + @q.push [:STRING, unescape($1)] str = $' else #c = str[0,1] #@q.push [:STRING, c] str = str[1..-1]