debian-control-0.1.1/.cargo_vcs_info.json0000644000000001360000000000100137330ustar { "git": { "sha1": "0f426f67327ad964cab5f481b27c732e26958dee" }, "path_in_vcs": "" }debian-control-0.1.1/.gitignore000064400000000000000000000000131046102023000145050ustar 00000000000000/target *~ debian-control-0.1.1/Cargo.lock0000644000000020340000000000100117050ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" dependencies = [ "memchr", ] [[package]] name = "debian-control" version = "0.1.1" dependencies = [ "regex", ] [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "regex" version = "1.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" debian-control-0.1.1/Cargo.toml0000644000000014530000000000100117340ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "debian-control" version = "0.1.1" authors = ["Jelmer Vernooij "] description = "A parser for Debian control files" homepage = "https://github.com/jelmer/debian-control-rs" license = "Apache-2.0" repository = "https://github.com/jelmer/debian-control-rs" [dependencies.regex] version = "1" debian-control-0.1.1/Cargo.toml.orig000064400000000000000000000005201046102023000154070ustar 00000000000000[package] name = "debian-control" authors = ["Jelmer Vernooij "] version = "0.1.1" edition = "2021" license = "Apache-2.0" description = "A parser for Debian control files" repository = "https://github.com/jelmer/debian-control-rs" homepage = "https://github.com/jelmer/debian-control-rs" [dependencies] regex = "1" debian-control-0.1.1/src/lib.rs000064400000000000000000000000151046102023000144220ustar 00000000000000pub mod vcs; debian-control-0.1.1/src/main.rs000064400000000000000000000000551046102023000146040ustar 00000000000000fn main() { println!("Hello, world!"); } debian-control-0.1.1/src/vcs.rs000064400000000000000000000055421046102023000144610ustar 00000000000000use regex::Regex; use std::borrow::Cow; use std::str::FromStr; #[derive(Debug, Clone)] pub struct VcsInfo { repo_url: String, branch: Option, subpath: Option, } impl FromStr for VcsInfo { type Err = &'static str; fn from_str(s: &str) -> Result { let mut s: Cow = s.trim().into(); let mut subpath: Option = None; let branch: Option; let repo_url: String; let re = Regex::new(r" \[([^] ]+)\]").unwrap(); if let Some(ref m) = re.find(s.as_ref()) { subpath = Some(m.as_str()[2..m.as_str().len() - 1].to_string()); s = Cow::Owned(vec![s[..m.start()].to_string(), s[m.end()..].to_string()].concat()); } if let Some(index) = s.find(" -b ") { let (url, branch_str) = s.split_at(index); branch = Some(branch_str[4..].to_string()); repo_url = url.to_string(); } else { branch = None; repo_url = s.to_string(); } Ok(VcsInfo { repo_url, branch, subpath, }) } } impl ToString for VcsInfo { fn to_string(&self) -> String { let mut url = self.repo_url.clone(); if let Some(branch) = &self.branch { url = format!("{} -b {}", url, branch); } if let Some(subpath) = &self.subpath { url = format!("{} [{}]", url, subpath); } url } } #[cfg(test)] mod test { use super::*; #[test] fn test_vcs_info() { let vcs_info = VcsInfo::from_str("https://github.com/jelmer/example").unwrap(); assert_eq!(vcs_info.repo_url, "https://github.com/jelmer/example"); assert_eq!(vcs_info.branch, None); assert_eq!(vcs_info.subpath, None); } #[test] fn test_vcs_info_with_branch() { let vcs_info = VcsInfo::from_str("https://github.com/jelmer/example -b branch").unwrap(); assert_eq!(vcs_info.repo_url, "https://github.com/jelmer/example"); assert_eq!(vcs_info.branch, Some("branch".to_string())); assert_eq!(vcs_info.subpath, None); } #[test] fn test_vcs_info_with_subpath() { let vcs_info = VcsInfo::from_str("https://github.com/jelmer/example [subpath]").unwrap(); assert_eq!(vcs_info.repo_url, "https://github.com/jelmer/example"); assert_eq!(vcs_info.branch, None); assert_eq!(vcs_info.subpath, Some("subpath".to_string())); } #[test] fn test_vcs_info_with_branch_and_subpath() { let vcs_info = VcsInfo::from_str("https://github.com/jelmer/example -b branch [subpath]").unwrap(); assert_eq!(vcs_info.repo_url, "https://github.com/jelmer/example"); assert_eq!(vcs_info.branch, Some("branch".to_string())); assert_eq!(vcs_info.subpath, Some("subpath".to_string())); } }