summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2023-08-04 10:59:28 +0200
committerLinus Färnstrand <linus@mullvad.net>2023-08-04 10:59:28 +0200
commitf5d5a5c7bf3889685c7c9fce9b53f85fd56e59b0 (patch)
tree1adbfba78ea23c04f9ecfed60fd57eff683fec33 /android
parentc1ac80e985e92a74cc580fd85b2e4f5b57c8c96d (diff)
parent6f64fb7cf49f23b0b00817ad2750dea860187140 (diff)
downloadmullvadvpn-f5d5a5c7bf3889685c7c9fce9b53f85fd56e59b0.tar.xz
mullvadvpn-f5d5a5c7bf3889685c7c9fce9b53f85fd56e59b0.zip
Merge branch 'replace-lazy_static-with-std-alternatives-des-226'
Diffstat (limited to 'android')
-rw-r--r--android/translations-converter/Cargo.toml2
-rw-r--r--android/translations-converter/src/android/string_value.rs11
-rw-r--r--android/translations-converter/src/normalize.rs18
3 files changed, 11 insertions, 20 deletions
diff --git a/android/translations-converter/Cargo.toml b/android/translations-converter/Cargo.toml
index 938f7503d8..8f3a7dca12 100644
--- a/android/translations-converter/Cargo.toml
+++ b/android/translations-converter/Cargo.toml
@@ -11,7 +11,7 @@ publish.workspace = true
[dependencies]
err-derive = "0.3.1"
htmlize = { version = "1.0.2", features = ["unescape"] }
-lazy_static = "1"
+once_cell = "1.13"
regex = "1"
serde = { version = "1", features = ["derive"] }
quick-xml = { version = "0.27.1", features = ["serialize"] }
diff --git a/android/translations-converter/src/android/string_value.rs b/android/translations-converter/src/android/string_value.rs
index c2f8e7a6ce..9513f3e096 100644
--- a/android/translations-converter/src/android/string_value.rs
+++ b/android/translations-converter/src/android/string_value.rs
@@ -1,4 +1,4 @@
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize};
use std::{
@@ -32,10 +32,7 @@ impl StringValue {
/// 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();
- }
-
+ static LINE_BREAKS: Lazy<Regex> = Lazy::new(|| Regex::new(r"\s*\n\s*").unwrap());
LINE_BREAKS.replace_all(&original, " ").into_owned()
}
@@ -46,9 +43,7 @@ impl StringValue {
/// would update the string so that all parameters have indices: `Things are %1$d, %3$s and
/// %4$s`.
fn ensure_parameters_are_indexed(original: String) -> String {
- lazy_static! {
- static ref PARAMETER_INDEX: Regex = Regex::new(r"^(\d+)\$").unwrap();
- }
+ static PARAMETER_INDEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(\d+)\$").unwrap());
let mut parts = original.split('%');
let mut output = parts.next().unwrap().to_owned();
diff --git a/android/translations-converter/src/normalize.rs b/android/translations-converter/src/normalize.rs
index 3992004bd2..1ea0ae9440 100644
--- a/android/translations-converter/src/normalize.rs
+++ b/android/translations-converter/src/normalize.rs
@@ -1,4 +1,4 @@
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use regex::Regex;
pub trait Normalize {
@@ -12,11 +12,9 @@ mod android {
use super::*;
use crate::android::StringValue;
- lazy_static! {
- 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();
- }
+ static APOSTROPHES: Lazy<Regex> = Lazy::new(|| Regex::new(r"\\'").unwrap());
+ static DOUBLE_QUOTES: Lazy<Regex> = Lazy::new(|| Regex::new(r#"\\""#).unwrap());
+ static PARAMETERS: Lazy<Regex> = Lazy::new(|| Regex::new(r"%[0-9]*\$").unwrap());
impl Normalize for StringValue {
fn normalize(&self) -> String {
@@ -37,11 +35,9 @@ mod gettext {
use super::*;
use crate::gettext::MsgString;
- lazy_static! {
- static ref ESCAPED_SINGLE_QUOTES: Regex = Regex::new(r"\\'").unwrap();
- static ref ESCAPED_DOUBLE_QUOTES: Regex = Regex::new(r#"\\""#).unwrap();
- static ref PARAMETERS: Regex = Regex::new(r"%\([^)]*\)").unwrap();
- }
+ static ESCAPED_SINGLE_QUOTES: Lazy<Regex> = Lazy::new(|| Regex::new(r"\\'").unwrap());
+ static ESCAPED_DOUBLE_QUOTES: Lazy<Regex> = Lazy::new(|| Regex::new(r#"\\""#).unwrap());
+ static PARAMETERS: Lazy<Regex> = Lazy::new(|| Regex::new(r"%\([^)]*\)").unwrap());
impl Normalize for MsgString {
fn normalize(&self) -> String {