diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-05-20 14:08:23 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-05-21 13:23:25 +0000 |
| commit | d2dcd09574927d3e1d1c7299310c153ae4118467 (patch) | |
| tree | 7bd7246259a943dedb097d5d0d794510d1730fc6 /android | |
| parent | e261fcb893d19dd1a3d96f26c24e072d29d091ea (diff) | |
| download | mullvadvpn-d2dcd09574927d3e1d1c7299310c153ae4118467.tar.xz mullvadvpn-d2dcd09574927d3e1d1c7299310c153ae4118467.zip | |
Impl. more escape sequences in gettext messages
Diffstat (limited to 'android')
| -rw-r--r-- | android/translations-converter/src/gettext/msg_string.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/android/translations-converter/src/gettext/msg_string.rs b/android/translations-converter/src/gettext/msg_string.rs index d693c4ee04..b6ae21aadf 100644 --- a/android/translations-converter/src/gettext/msg_string.rs +++ b/android/translations-converter/src/gettext/msg_string.rs @@ -17,9 +17,17 @@ impl MsgString { /// Create a new `MsgString` from string without any escaped characters. /// - /// This will ensure that the string has the double quotes characters properly escaped. + /// This will ensure that the string has common C escape sequences properly created for special + /// characters. It will not attempt to escape non-ASCII characters and will just keep them as + /// UTF-8 characters. pub fn from_unescaped(string: &str) -> Self { - MsgString(string.replace(r#"""#, r#"\""#)) + let string = string.replace(r"\", r"\\"); + let string = string.replace("\n", r"\n"); + let string = string.replace("\r", r"\r"); + let string = string.replace("\t", r"\t"); + let string = string.replace(r#"""#, r#"\""#); + + MsgString(string) } /// Create a new `MsgString` from string that already has proper escaping. @@ -56,9 +64,19 @@ mod tests { #[test] fn escaping() { - let input = MsgString::from_unescaped(r#""Inside double quotes""#); + let input = MsgString::from_unescaped(concat!( + r#""Inside double quotes""#, + r"'Inside single quotes'", + r"Back-slash character: \", + "Whitespace characters: \n\r\t", + )); - let expected = r#"\"Inside double quotes\""#; + let expected = concat!( + r#"\"Inside double quotes\""#, + "'Inside single quotes'", + r"Back-slash character: \\", + r"Whitespace characters: \n\r\t", + ); assert_eq!(input.to_string(), expected); } |
