diff options
Diffstat (limited to 'support/texlab/crates/base-feature/src')
-rw-r--r-- | support/texlab/crates/base-feature/src/lib.rs | 4 | ||||
-rw-r--r-- | support/texlab/crates/base-feature/src/normalize_uri.rs | 56 | ||||
-rw-r--r-- | support/texlab/crates/base-feature/src/placeholders.rs | 50 |
3 files changed, 0 insertions, 110 deletions
diff --git a/support/texlab/crates/base-feature/src/lib.rs b/support/texlab/crates/base-feature/src/lib.rs deleted file mode 100644 index 589ec20de4..0000000000 --- a/support/texlab/crates/base-feature/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod normalize_uri; -mod placeholders; - -pub use self::{normalize_uri::normalize_uri, placeholders::*}; diff --git a/support/texlab/crates/base-feature/src/normalize_uri.rs b/support/texlab/crates/base-feature/src/normalize_uri.rs deleted file mode 100644 index 041258e817..0000000000 --- a/support/texlab/crates/base-feature/src/normalize_uri.rs +++ /dev/null @@ -1,56 +0,0 @@ -use url::Url; - -pub fn normalize_uri(uri: &mut Url) { - if let Some(mut segments) = uri.path_segments() { - if let Some(mut path) = segments.next().and_then(fix_drive_letter) { - for segment in segments { - path.push('/'); - path.push_str(segment); - } - - uri.set_path(&path); - } - } - - uri.set_fragment(None); -} - -fn fix_drive_letter(text: &str) -> Option<String> { - if !text.is_ascii() { - return None; - } - - match &text[1..] { - ":" => Some(text.to_ascii_uppercase()), - "%3A" | "%3a" => Some(format!("{}:", text[0..1].to_ascii_uppercase())), - _ => None, - } -} - -#[cfg(test)] -mod tests { - use url::Url; - - use super::normalize_uri; - - #[test] - fn test_lowercase_drive_letter() { - let mut uri = Url::parse("file://c:/foo/bar.txt").unwrap(); - normalize_uri(&mut uri); - assert_eq!(uri.as_str(), "file:///C:/foo/bar.txt"); - } - - #[test] - fn test_uppercase_drive_letter() { - let mut uri = Url::parse("file://C:/foo/bar.txt").unwrap(); - normalize_uri(&mut uri); - assert_eq!(uri.as_str(), "file:///C:/foo/bar.txt"); - } - - #[test] - fn test_fragment() { - let mut uri = Url::parse("foo:///bar/baz.txt#qux").unwrap(); - normalize_uri(&mut uri); - assert_eq!(uri.as_str(), "foo:///bar/baz.txt"); - } -} diff --git a/support/texlab/crates/base-feature/src/placeholders.rs b/support/texlab/crates/base-feature/src/placeholders.rs deleted file mode 100644 index 913af33edf..0000000000 --- a/support/texlab/crates/base-feature/src/placeholders.rs +++ /dev/null @@ -1,50 +0,0 @@ -use rustc_hash::FxHashMap; - -pub fn replace_placeholders(args: &[String], pairs: &[(char, &str)]) -> Vec<String> { - let map = FxHashMap::from_iter(pairs.iter().copied()); - args.iter() - .map(|input| { - let quoted = input - .strip_prefix('"') - .and_then(|input| input.strip_suffix('"')); - - match quoted { - Some(output) => String::from(output), - None => { - let mut output = String::new(); - let mut chars = input.chars(); - while let Some(ch) = chars.next() { - if ch == '%' { - match chars.next() { - Some(key) => match map.get(&key) { - Some(value) => output.push_str(&value), - None => output.push(key), - }, - None => output.push('%'), - }; - } else { - output.push(ch); - } - } - - output - } - } - }) - .collect() -} - -#[cfg(test)] -mod tests { - use super::replace_placeholders; - - #[test] - fn test_quoted() { - let output = replace_placeholders( - &["foo".into(), "\"%f\"".into(), "%%f".into(), "%fbar".into()], - &[('f', "foo")], - ); - - assert_eq!(output, vec!["foo".into(), "%f", "%f".into(), "foobar"]); - } -} |