Compare commits
15 commits
0.x
...
sapling-pr
| Author | SHA1 | Date | |
|---|---|---|---|
| 4105928b9a | |||
| 3f21759c47 | |||
| e3f52b573b | |||
| 817c994da8 | |||
| ea6547861a | |||
| 832428dbf1 | |||
| 9fc7a737eb | |||
| 89889def72 | |||
| dc5fbc4026 | |||
| 568e618106 | |||
| 2617363f4f | |||
| bb03e09764 | |||
| fa9e139e36 | |||
| 08d96f8ea4 | |||
| d0b4ad2046 |
2 changed files with 19 additions and 1 deletions
|
|
@ -26,6 +26,12 @@ pub fn replace(search: &String, replace: String, input: String) -> String {
|
||||||
let start = search_match.start();
|
let start = search_match.start();
|
||||||
let end = search_match.end();
|
let end = search_match.end();
|
||||||
|
|
||||||
|
// Prevent an infinite loop. If we hit this condition we will keep adding a new replacement
|
||||||
|
// to the end.
|
||||||
|
if start == end {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let mut replacement = String::new();
|
let mut replacement = String::new();
|
||||||
match search_pattern.captures(&output[start..end]) {
|
match search_pattern.captures(&output[start..end]) {
|
||||||
Some(captures) => {
|
Some(captures) => {
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,16 @@ Feature: Regex search and replace
|
||||||
Given Search is '(\w+'
|
Given Search is '(\w+'
|
||||||
And Replace is 'new'
|
And Replace is 'new'
|
||||||
And Input is 'this is a'
|
And Input is 'this is a'
|
||||||
Then Output is 'this is a'
|
Then Output is 'this is a'
|
||||||
|
|
||||||
|
Scenario: You can replace a pattern with a dot in it like a css class name
|
||||||
|
Given Search is '.testing'
|
||||||
|
And Replace is '.another'
|
||||||
|
And Input is '.testing {'
|
||||||
|
Then Output is '.another {'
|
||||||
|
|
||||||
|
Scenario: You can replace a pattern that grabs all the text
|
||||||
|
Given Search is '.*'
|
||||||
|
And Replace is '.another'
|
||||||
|
And Input is '.testing {'
|
||||||
|
Then Output is '.another'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue