Centralized escape_quotes helper method in Abstract formatter.
This commit is contained in:
parent
7691068e05
commit
d690adb322
7 changed files with 7 additions and 22 deletions
|
@ -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'
|
||||
|
||||
|
|
|
@ -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/%@)
|
||||
|
|
|
@ -109,11 +109,6 @@ module Twine
|
|||
def format_value(value)
|
||||
escape_quotes(value)
|
||||
end
|
||||
|
||||
def escape_quotes(text)
|
||||
text.gsub('"', '\\\\"')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -134,10 +134,6 @@ module Twine
|
|||
def format_value(value)
|
||||
escape_quotes(value)
|
||||
end
|
||||
|
||||
def escape_quotes(text)
|
||||
text.gsub('"', '\\\\"')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -94,10 +94,6 @@ module Twine
|
|||
def format_comment(comment)
|
||||
"#. \"#{escape_quotes(comment)}\""
|
||||
end
|
||||
|
||||
def escape_quotes(text)
|
||||
text.gsub('"', '\\\\"')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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/%@)
|
||||
|
|
Reference in a new issue