diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-05-14 21:50:27 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-05-19 12:13:36 +0000 |
| commit | b6328d418ac810621377853591408ab392aa32ca (patch) | |
| tree | 2baf8acdb1b8ec8b6cee3f40765dde597430f1f3 /android | |
| parent | b792e8d9754bc498df6a2cf62beb1740a073af7c (diff) | |
| download | mullvadvpn-b6328d418ac810621377853591408ab392aa32ca.tar.xz mullvadvpn-b6328d418ac810621377853591408ab392aa32ca.zip | |
Move collapsing line breaks to constructor
This is because the removal of line breaks is not part of the
normalization but part of initial conditioning of the input.
Diffstat (limited to 'android')
| -rw-r--r-- | android/translations-converter/src/android/string_value.rs | 13 | ||||
| -rw-r--r-- | android/translations-converter/src/normalize.rs | 5 |
2 files changed, 13 insertions, 5 deletions
diff --git a/android/translations-converter/src/android/string_value.rs b/android/translations-converter/src/android/string_value.rs index b0bff135a4..9207dad6ed 100644 --- a/android/translations-converter/src/android/string_value.rs +++ b/android/translations-converter/src/android/string_value.rs @@ -18,11 +18,22 @@ impl StringValue { .replace("\"", "\\\"") .replace(r"'", r"\'"); - let value = Self::ensure_parameters_are_indexed(value_with_parameters); + let value_without_line_breaks = Self::collapse_line_breaks(value_with_parameters); + let value = Self::ensure_parameters_are_indexed(value_without_line_breaks); StringValue(value) } + /// The input XML file might have line breaks inside the string, and they should be collapsed + /// into a single whitespace character. + fn collapse_line_breaks(original: String) -> String { + lazy_static! { + static ref LINE_BREAKS: Regex = Regex::new(r"\s*\n\s*").unwrap(); + } + + LINE_BREAKS.replace_all(&original, " ").into_owned() + } + /// This helper method ensures parameters are in the form of `%4$d`, i.e., it will ensure that /// there is the `<number>$` part. /// diff --git a/android/translations-converter/src/normalize.rs b/android/translations-converter/src/normalize.rs index 56c45d661e..4903c10911 100644 --- a/android/translations-converter/src/normalize.rs +++ b/android/translations-converter/src/normalize.rs @@ -13,7 +13,6 @@ mod android { use crate::android::StringValue; lazy_static! { - static ref LINE_BREAKS: Regex = Regex::new(r"\s*\n\s*").unwrap(); static ref APOSTROPHES: Regex = Regex::new(r"\\'").unwrap(); static ref DOUBLE_QUOTES: Regex = Regex::new(r#"\\""#).unwrap(); static ref PARAMETERS: Regex = Regex::new(r"%[0-9]*\$").unwrap(); @@ -21,10 +20,8 @@ mod android { impl Normalize for StringValue { fn normalize(&self) -> String { - // Collapse line breaks present in the XML file - let value = LINE_BREAKS.replace_all(&*self, " "); // Unescape apostrophes - let value = APOSTROPHES.replace_all(&value, "'"); + let value = APOSTROPHES.replace_all(&*self, "'"); // Unescape double quotes let value = DOUBLE_QUOTES.replace_all(&value, r#"""#); // Mark where parameters are positioned, removing the parameter index |
