Centralized escape_quotes helper method in Abstract formatter.

This commit is contained in:
Sebastian Ludwig 2015-11-28 15:07:32 +01:00
parent 7691068e05
commit d690adb322
7 changed files with 7 additions and 22 deletions

View file

@ -195,6 +195,10 @@ module Twine
value
end
def escape_quotes(text)
text.gsub('"', '\\\\"')
end
def write_file(path, lang)
encoding = @options[:output_encoding] || 'UTF-8'

View file

@ -114,11 +114,10 @@ module Twine
end
def format_value(value)
value = value.dup
# Android enforces the following rules on the values
# 1) apostrophes and quotes must be escaped with a backslash
value = escape_quotes(value)
value.gsub!("'", "\\\\'")
value.gsub!('"', '\\\\"')
# 2) HTML escape the string
value = CGI.escapeHTML(value)
# 3) fix substitutions (e.g. %s/%@)

View file

@ -109,11 +109,6 @@ module Twine
def format_value(value)
escape_quotes(value)
end
def escape_quotes(text)
text.gsub('"', '\\\\"')
end
end
end
end

View file

@ -134,10 +134,6 @@ module Twine
def format_value(value)
escape_quotes(value)
end
def escape_quotes(text)
text.gsub('"', '\\\\"')
end
end
end
end

View file

@ -94,10 +94,6 @@ module Twine
def format_comment(comment)
"#. \"#{escape_quotes(comment)}\""
end
def escape_quotes(text)
text.gsub('"', '\\\\"')
end
end
end
end

View file

@ -70,17 +70,13 @@ module Twine
end
def format_key(key)
escape_quotes(key) # TODO: solve this better
escape_quotes(key)
end
def format_value(value)
escape_quotes(value)
end
def escape_quotes(text)
text.gsub('"', '\\\\"')
end
def write_file(path, lang)
begin
require "json"

View file

@ -140,11 +140,10 @@ module Twine
end
def format_value(value)
value = value.dup
value = escape_quotes(value)
# Tizen enforces the following rules on the values
# 1) apostrophes and quotes must be escaped with a backslash
value.gsub!("'", "\\\\'")
value.gsub!('"', '\\\\"')
# 2) HTML escape the string
value = CGI.escapeHTML(value)
# 3) fix substitutions (e.g. %s/%@)