Skip to content

Commit

Permalink
chore: remove pcre2 deps (#1220)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Apr 15, 2024
1 parent bc61341 commit 3582ed1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 44 deletions.
34 changes: 1 addition & 33 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kclvm/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ kclvm-version = {path = "../version"}
kclvm-utils = {path = "../utils"}
kclvm-ast = {path = "../ast"}
dirs = "5.0.0"
pcre2 = "0.2.4"
md-5 = "0.8.0"
regex = "1.10.4"
16 changes: 6 additions & 10 deletions kclvm/config/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! `${my_pkg:KCL_MOD}/sub/main.k` is a mod relative path.
//! The real path of `${my_pkg:KCL_MOD}/xxx/main.k` is `/usr/my_pkg/sub/main.k`.
use anyhow::Result;
use pcre2::bytes::Regex;
use regex::Regex;
use std::path::PathBuf;

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -72,7 +72,7 @@ impl ModRelativePath {
/// ```
pub fn is_relative_path(&self) -> Result<bool> {
Ok(Regex::new(RELATIVE_PATH_PREFFIX)?
.find(self.path.as_bytes())?
.find(&self.path)
.map_or(false, |mat| mat.start() == 0))
}

Expand All @@ -97,10 +97,9 @@ impl ModRelativePath {
}

Ok(Regex::new(RELATIVE_PATH_PREFFIX)?
.captures(self.path.as_bytes())?
.captures(&self.path)
.and_then(|caps| caps.name(ROOT_PKG_NAME_FLAG))
.map(|mat| std::str::from_utf8(mat.as_bytes()).map(|s| s.to_string()))
.transpose()?)
.map(|mat| mat.as_str().to_string()))
}

/// [`canonicalize_by_root_path`] returns the canonicalized path by the root path.
Expand All @@ -124,17 +123,14 @@ impl ModRelativePath {
}

Ok(Regex::new(RELATIVE_PATH_PREFFIX)?
.captures(self.path.as_bytes())?
.captures(&self.path)
.map_or_else(
|| self.get_path(),
|caps| {
// Due to the path format is different between windows and linux,
// Can not use the replace method directly
// by 'replace(std::str::from_utf8(caps.get(0).unwrap().as_bytes()).unwrap(), root_path)'.
let sub_path = self.get_path().replace(
std::str::from_utf8(caps.get(0).unwrap().as_bytes()).unwrap(),
"",
);
let sub_path = self.get_path().replace(caps.get(0).unwrap().as_str(), "");
let res = PathBuf::from(root_path)
.join(sub_path)
.display()
Expand Down

0 comments on commit 3582ed1

Please sign in to comment.