diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-04-06 22:34:52 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-05-19 12:13:36 +0000 |
| commit | 56e30f0fbae11a847af17e1adedf097b384b3ed8 (patch) | |
| tree | b767facae728fc9f985c06622021ce375bc0d060 | |
| parent | b8913b37774bb4801b9c551e170706aa0107f279 (diff) | |
| download | mullvadvpn-56e30f0fbae11a847af17e1adedf097b384b3ed8.tar.xz mullvadvpn-56e30f0fbae11a847af17e1adedf097b384b3ed8.zip | |
Move `MsgString` type into a separate module
| -rw-r--r-- | android/translations-converter/src/gettext/mod.rs | 35 | ||||
| -rw-r--r-- | android/translations-converter/src/gettext/msg_string.rs | 35 |
2 files changed, 38 insertions, 32 deletions
diff --git a/android/translations-converter/src/gettext/mod.rs b/android/translations-converter/src/gettext/mod.rs index c496775ee2..ae71e1ed7c 100644 --- a/android/translations-converter/src/gettext/mod.rs +++ b/android/translations-converter/src/gettext/mod.rs @@ -1,12 +1,13 @@ +mod msg_string; + +use self::msg_string::MsgString; use lazy_static::lazy_static; use regex::Regex; use std::{ collections::BTreeMap, - fmt::{self, Display, Formatter}, fs::{File, OpenOptions}, io::{self, BufRead, BufReader, BufWriter, Write}, mem, - ops::Deref, path::Path, }; @@ -50,10 +51,6 @@ pub enum MsgValue { }, } -/// A message string in a gettext translation file. -#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct MsgString(String); - /// A helper macro to match a string to various prefix and suffix combinations. macro_rules! match_str { ( @@ -223,32 +220,6 @@ impl PluralForm { } } -impl From<String> for MsgString { - fn from(string: String) -> Self { - MsgString(string) - } -} - -impl From<&str> for MsgString { - fn from(string: &str) -> Self { - string.to_owned().into() - } -} - -impl Display for MsgString { - /// Write the ID message string with proper escaping. - fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { - self.0.replace(r#"""#, r#"\""#).fmt(formatter) - } -} - -impl Deref for MsgString { - type Target = str; - - fn deref(&self) -> &Self::Target { - self.0.as_str() - } -} impl From<String> for MsgValue { fn from(string: String) -> Self { diff --git a/android/translations-converter/src/gettext/msg_string.rs b/android/translations-converter/src/gettext/msg_string.rs new file mode 100644 index 0000000000..7419b6bd94 --- /dev/null +++ b/android/translations-converter/src/gettext/msg_string.rs @@ -0,0 +1,35 @@ +use std::{ + fmt::{self, Display, Formatter}, + ops::Deref, +}; + +/// A message string in a gettext translation file. +#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct MsgString(String); + +impl From<String> for MsgString { + fn from(string: String) -> Self { + MsgString(string) + } +} + +impl From<&str> for MsgString { + fn from(string: &str) -> Self { + string.to_owned().into() + } +} + +impl Display for MsgString { + /// Write the ID message string with proper escaping. + fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { + self.0.replace(r#"""#, r#"\""#).fmt(formatter) + } +} + +impl Deref for MsgString { + type Target = str; + + fn deref(&self) -> &Self::Target { + self.0.as_str() + } +} |
