Skip to content

Commit 2f57f6d

Browse files
committed
clippy: fix trivial_regex
Dropped a dep. Good.
1 parent ea361ff commit 2f57f6d

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ num_cpus = "1.11"
2323
cc = "1.0"
2424
pkg-config = "0.3"
2525
bindgen = "0.54"
26-
regex = "1.3"
2726

2827
[features]
2928
default = ["avcodec", "avdevice", "avfilter", "avformat", "swresample", "swscale"]

build.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ extern crate bindgen;
22
extern crate cc;
33
extern crate num_cpus;
44
extern crate pkg_config;
5-
extern crate regex;
65

76
use std::env;
87
use std::fs::{self, File};
@@ -14,7 +13,6 @@ use std::str;
1413
use bindgen::callbacks::{
1514
EnumVariantCustomBehavior, EnumVariantValue, IntKind, MacroParsingBehavior, ParseCallbacks,
1615
};
17-
use regex::Regex;
1816

1917
#[derive(Debug)]
2018
struct Library {
@@ -76,22 +74,22 @@ struct Callbacks;
7674

7775
impl ParseCallbacks for Callbacks {
7876
fn int_macro(&self, _name: &str, value: i64) -> Option<IntKind> {
79-
let ch_layout = Regex::new(r"^AV_CH").unwrap();
80-
let codec_cap = Regex::new(r"^AV_CODEC_CAP").unwrap();
81-
let codec_flag = Regex::new(r"^AV_CODEC_FLAG").unwrap();
82-
let error_max_size = Regex::new(r"^AV_ERROR_MAX_STRING_SIZE").unwrap();
77+
let ch_layout_prefix = "AV_CH_";
78+
let codec_cap_prefix = "AV_CODEC_CAP_";
79+
let codec_flag_prefix = "AV_CODEC_FLAG_";
80+
let error_max_size = "AV_ERROR_MAX_STRING_SIZE";
8381

8482
if value >= i64::min_value() as i64
8583
&& value <= i64::max_value() as i64
86-
&& ch_layout.is_match(_name)
84+
&& _name.starts_with(ch_layout_prefix)
8785
{
8886
Some(IntKind::ULongLong)
8987
} else if value >= i32::min_value() as i64
9088
&& value <= i32::max_value() as i64
91-
&& (codec_cap.is_match(_name) || codec_flag.is_match(_name))
89+
&& (_name.starts_with(codec_cap_prefix) || _name.starts_with(codec_flag_prefix))
9290
{
9391
Some(IntKind::UInt)
94-
} else if error_max_size.is_match(_name) {
92+
} else if _name == error_max_size {
9593
Some(IntKind::Custom {
9694
name: "usize",
9795
is_signed: false,
@@ -109,8 +107,8 @@ impl ParseCallbacks for Callbacks {
109107
original_variant_name: &str,
110108
_variant_value: EnumVariantValue,
111109
) -> Option<EnumVariantCustomBehavior> {
112-
let dummy_codec_id = Regex::new(r"^AV_CODEC_ID_FIRST").unwrap();
113-
if dummy_codec_id.is_match(original_variant_name) {
110+
let dummy_codec_id_prefix = "AV_CODEC_ID_FIRST_";
111+
if original_variant_name.starts_with(dummy_codec_id_prefix) {
114112
Some(EnumVariantCustomBehavior::Constify)
115113
} else {
116114
None

0 commit comments

Comments
 (0)