-
Notifications
You must be signed in to change notification settings - Fork 20
feat: change regex to regex-lite #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
f194da5
9d618ed
b46ea85
42466da
cbebdc1
a9fc202
e93a573
94970f7
d2a1974
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use regex::Regex; | ||
| use std::env; | ||
| use std::sync::LazyLock; | ||
|
|
||
|
|
@@ -104,13 +103,23 @@ impl AzureMetadata { | |
| } | ||
|
|
||
| fn extract_resource_group(s: Option<String>) -> Option<String> { | ||
| #[allow(clippy::unwrap_used)] | ||
| let re: Regex = Regex::new(r".+\+(.+)-.+webspace(-Linux)?").unwrap(); | ||
|
|
||
| s.as_ref().and_then(|text| { | ||
| re.captures(text) | ||
| .and_then(|caps| caps.get(1).map(|m| m.as_str().to_string())) | ||
| }) | ||
| // /.+\+(.+)-.+webspace(-Linux)?/ | ||
| let text = s.as_ref()?; | ||
| let (before_plus, after_plus) = text.rsplit_once('+')?; | ||
| if before_plus.is_empty() { | ||
| return None; | ||
| } | ||
| let webspace_pos = after_plus.rfind("webspace")?; | ||
| let before_webspace = &after_plus[..webspace_pos]; | ||
| let dash_pos = before_webspace.rfind('-')?; | ||
| if dash_pos + 1 >= before_webspace.len() { | ||
| return None; | ||
| } | ||
| let resource_group = &before_webspace[..dash_pos]; | ||
| if resource_group.is_empty() { | ||
| return None; | ||
| } | ||
| Some(resource_group.to_string()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, the behavior of this parser is different from the original regexp. For example,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep since this was mostly about capturing the correct thing I omitted that, I don't know if it's relevant, I should check with the consumers of this |
||
| } | ||
|
|
||
| /* | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.