Skip to content

Commit 7b3038e

Browse files
committed
Store original strings in RegexSet
1 parent 371e744 commit 7b3038e

File tree

2 files changed

+18
-77
lines changed

2 files changed

+18
-77
lines changed

src/lib.rs

+15-75
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,7 @@ impl Builder {
233233
.iter()
234234
.map(|item| {
235235
output_vector.push("--bitfield-enum".into());
236-
output_vector.push(
237-
item.trim_left_matches("^")
238-
.trim_right_matches("$")
239-
.into(),
240-
);
236+
output_vector.push(item.to_owned());
241237
})
242238
.count();
243239

@@ -247,11 +243,7 @@ impl Builder {
247243
.iter()
248244
.map(|item| {
249245
output_vector.push("--rustified-enum".into());
250-
output_vector.push(
251-
item.trim_left_matches("^")
252-
.trim_right_matches("$")
253-
.into(),
254-
);
246+
output_vector.push(item.to_owned());
255247
})
256248
.count();
257249

@@ -261,11 +253,7 @@ impl Builder {
261253
.iter()
262254
.map(|item| {
263255
output_vector.push("--constified-enum-module".into());
264-
output_vector.push(
265-
item.trim_left_matches("^")
266-
.trim_right_matches("$")
267-
.into(),
268-
);
256+
output_vector.push(item.to_owned());
269257
})
270258
.count();
271259

@@ -275,11 +263,7 @@ impl Builder {
275263
.iter()
276264
.map(|item| {
277265
output_vector.push("--constified-enum".into());
278-
output_vector.push(
279-
item.trim_left_matches("^")
280-
.trim_right_matches("$")
281-
.into(),
282-
);
266+
output_vector.push(item.to_owned());
283267
})
284268
.count();
285269

@@ -289,11 +273,7 @@ impl Builder {
289273
.iter()
290274
.map(|item| {
291275
output_vector.push("--blacklist-type".into());
292-
output_vector.push(
293-
item.trim_left_matches("^")
294-
.trim_right_matches("$")
295-
.into(),
296-
);
276+
output_vector.push(item.to_owned());
297277
})
298278
.count();
299279

@@ -303,11 +283,7 @@ impl Builder {
303283
.iter()
304284
.map(|item| {
305285
output_vector.push("--blacklist-function".into());
306-
output_vector.push(
307-
item.trim_left_matches("^")
308-
.trim_right_matches("$")
309-
.into(),
310-
);
286+
output_vector.push(item.to_owned());
311287
})
312288
.count();
313289

@@ -317,11 +293,7 @@ impl Builder {
317293
.iter()
318294
.map(|item| {
319295
output_vector.push("--blacklist-item".into());
320-
output_vector.push(
321-
item.trim_left_matches("^")
322-
.trim_right_matches("$")
323-
.into(),
324-
);
296+
output_vector.push(item.to_owned());
325297
})
326298
.count();
327299

@@ -472,11 +444,7 @@ impl Builder {
472444
.iter()
473445
.map(|item| {
474446
output_vector.push("--opaque-type".into());
475-
output_vector.push(
476-
item.trim_left_matches("^")
477-
.trim_right_matches("$")
478-
.into(),
479-
);
447+
output_vector.push(item.to_owned());
480448
})
481449
.count();
482450

@@ -485,11 +453,7 @@ impl Builder {
485453
.iter()
486454
.map(|item| {
487455
output_vector.push("--raw-line".into());
488-
output_vector.push(
489-
item.trim_left_matches("^")
490-
.trim_right_matches("$")
491-
.into(),
492-
);
456+
output_vector.push(item.to_owned());
493457
})
494458
.count();
495459

@@ -507,11 +471,7 @@ impl Builder {
507471
.iter()
508472
.map(|item| {
509473
output_vector.push("--whitelist-function".into());
510-
output_vector.push(
511-
item.trim_left_matches("^")
512-
.trim_right_matches("$")
513-
.into(),
514-
);
474+
output_vector.push(item.to_owned());
515475
})
516476
.count();
517477

@@ -521,11 +481,7 @@ impl Builder {
521481
.iter()
522482
.map(|item| {
523483
output_vector.push("--whitelist-type".into());
524-
output_vector.push(
525-
item.trim_left_matches("^")
526-
.trim_right_matches("$")
527-
.into(),
528-
);
484+
output_vector.push(item.to_owned());
529485
})
530486
.count();
531487

@@ -535,11 +491,7 @@ impl Builder {
535491
.iter()
536492
.map(|item| {
537493
output_vector.push("--whitelist-var".into());
538-
output_vector.push(
539-
item.trim_left_matches("^")
540-
.trim_right_matches("$")
541-
.into(),
542-
);
494+
output_vector.push(item.to_owned());
543495
})
544496
.count();
545497

@@ -576,11 +528,7 @@ impl Builder {
576528
.iter()
577529
.map(|item| {
578530
output_vector.push("--no-partialeq".into());
579-
output_vector.push(
580-
item.trim_left_matches("^")
581-
.trim_right_matches("$")
582-
.into(),
583-
);
531+
output_vector.push(item.to_owned());
584532
})
585533
.count();
586534

@@ -590,11 +538,7 @@ impl Builder {
590538
.iter()
591539
.map(|item| {
592540
output_vector.push("--no-copy".into());
593-
output_vector.push(
594-
item.trim_left_matches("^")
595-
.trim_right_matches("$")
596-
.into(),
597-
);
541+
output_vector.push(item.to_owned());
598542
})
599543
.count();
600544

@@ -604,11 +548,7 @@ impl Builder {
604548
.iter()
605549
.map(|item| {
606550
output_vector.push("--no-hash".into());
607-
output_vector.push(
608-
item.trim_left_matches("^")
609-
.trim_right_matches("$")
610-
.into(),
611-
);
551+
output_vector.push(item.to_owned());
612552
})
613553
.count();
614554

src/regex_set.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl RegexSet {
2020
where
2121
S: AsRef<str>,
2222
{
23-
self.items.push(format!("^{}$", string.as_ref()));
23+
self.items.push(string.as_ref().to_owned());
2424
self.set = None;
2525
}
2626

@@ -34,7 +34,8 @@ impl RegexSet {
3434
/// Must be called before calling `matches()`, or it will always return
3535
/// false.
3636
pub fn build(&mut self) {
37-
self.set = match RxSet::new(&self.items) {
37+
let items = self.items.iter().map(|item| format!("^{}$", item));
38+
self.set = match RxSet::new(items) {
3839
Ok(x) => Some(x),
3940
Err(e) => {
4041
error!("Invalid regex in {:?}: {:?}", self.items, e);

0 commit comments

Comments
 (0)