Class: Applocale::ContentUtil
- Inherits:
-
Object
- Object
- Applocale::ContentUtil
- Defined in:
- lib/applocale/Util/regex_util.rb
Constant Summary collapse
- REGEX_ESCAPED_QUOTE =
/(?<!\\)(?:\\{2})*(\\")/
- REGEX_NON_ESCAPE_QUOTE =
/(?<!\\)(?:\\{2})*(")/
Class Method Summary collapse
- .add_escape(platform, content) ⇒ Object
- .add_escaped_android(content) ⇒ Object
- .add_escaped_double_quote(content) ⇒ Object
- .from_excel(content) ⇒ Object
- .remove_escape(platform, content) ⇒ Object
- .remove_escaped_android(content) ⇒ Object
- .remove_escaped_double_quote(content) ⇒ Object
- .remove_escaped_new_line(content) ⇒ Object
Class Method Details
.add_escape(platform, content) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/applocale/Util/regex_util.rb', line 30 def self.add_escape(platform, content) if platform == Platform::IOS return self.add_escaped_double_quote(content) elsif platform == Platform::ANDROID return self.add_escaped_android(content) end return content end |
.add_escaped_android(content) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/applocale/Util/regex_util.rb', line 39 def self.add_escaped_android(content) new_value = content new_value = new_value.gsub(/'/, "\\'") reg = /(?<!\\)((?:\\{2})+)*(\\r)/ new_value = new_value.gsub(reg) {|match| match.slice!(-1) match + 'n' } reg = /(?<!\\)((?:\\{2})+)"|(?<!\\)"|^"/ new_value = new_value.gsub(reg) {|match| "\\" + match } new_value = new_value.gsub(/&/, '&') new_value = new_value.gsub(/%@/, '%s') new_value = new_value.gsub(/</, '<') new_value = new_value.gsub(/>/, '>') return new_value end |
.add_escaped_double_quote(content) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/applocale/Util/regex_util.rb', line 65 def self.add_escaped_double_quote(content) new_value = content reg = /(?<!\\)((?:\\{2})+)"|(?<!\\)"|^"/ new_value = new_value.gsub(reg) {|match| "\\" + match } return new_value end |
.from_excel(content) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/applocale/Util/regex_util.rb', line 83 def self.from_excel(content) reg = /(?<!\\)((?:\\{2})+)*\\"/ new_value = content.gsub(reg) {|match| match.slice!(0) match } new_value = new_value.gsub(/\n/, "\\n") new_value = new_value.gsub(/\t/, "\\t") return new_value end |
.remove_escape(platform, content) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/applocale/Util/regex_util.rb', line 21 def self.remove_escape(platform, content) if platform == Platform::IOS return self.remove_escaped_double_quote(content) elsif platform == Platform::ANDROID return self.remove_escaped_android(content) end return content end |
.remove_escaped_android(content) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/applocale/Util/regex_util.rb', line 58 def self.remove_escaped_android(content) new_value = content new_value = new_value.gsub(/%s/, '%@') new_value = new_value.gsub(/\\'/, "'") return new_value end |
.remove_escaped_double_quote(content) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/applocale/Util/regex_util.rb', line 74 def self.remove_escaped_double_quote(content) reg = /(?<!\\)((?:\\{2})+)*\\"/ new_value = content.gsub(reg) {|match| match.slice!(0) match } return new_value end |
.remove_escaped_new_line(content) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/applocale/Util/regex_util.rb', line 94 def self.remove_escaped_new_line(content) reg = /(?<!\\)((?:\\{2})+)*\\"/ new_value = content.gsub(reg) {|match| match.slice!(0) match } new_value .gsub(/\\n/, "\n") .gsub(/\\t/, "\t") end |