-
Notifications
You must be signed in to change notification settings - Fork 25
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
Use new algorithm for line replacements #39
Conversation
1986e58
to
6d35c1b
Compare
9f4b65f
to
657d816
Compare
Codecov Report
@@ Coverage Diff @@
## master #39 +/- ##
==========================================
+ Coverage 74.55% 78.89% +4.34%
==========================================
Files 8 7 -1
Lines 334 379 +45
==========================================
+ Hits 249 299 +50
+ Misses 85 80 -5 |
cb38ace
to
791f7fc
Compare
TODO: somehow the original error is lost when opening or writing a file fails. Needs more investigation |
Cool :) Seems pretty hard to review though... |
Yeah - there's lots of stuff going on. I'll open smaller pull requests to make review easier. |
7a97f23
to
3436642
Compare
Sorry. Holliday's. Will check :) |
91661a3
to
ea70390
Compare
6167536
to
dfcd2b2
Compare
Note for reviewers: I'm finally happy with the shape of the code, tell me if the diff is too hard to review and I try to split in more commits |
Instead of using the difference crate, compute a list of indexes ourselves and use it to print patches.
dfcd2b2
to
8c5c5ed
Compare
let c = chars[i]; | ||
print!("{}", c); | ||
i += 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there really no way to factorize this loop? Here's my intuition:
// put this in print_self:
let line = self.apply(input, |old, _new| old.red().underline());
println!(line);
// with:
pub fn apply(&self, input: &str, transform: &Fn<(old:str, new:str) -> String>) -> String {
let chars: Vec<_> = input.chars().collect();
let mut i = 0;
let mut res = String::new();
while i < input.len() {
if let Some(ReplaceValue { end_pos, new, .. }) = self.values.get(&i) {
let old = &input[i..*end_pos];
res.push_str(transform(old,new)); // <<<< called here
i = *end_pos;
} else {
let c = chars[i];
res.push(c);
i += 1;
}
}
res
}
Please forgive my rust, it might not compile and express ideas that are against the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for such a comment :) Did not thought about taking a closure as parameter, let me see if I can make it compile
Also, the code crashes:
Use |
There is no guarantee that input.len() is equal to chars.len()!
Update from fifi:
|
Also also the new algo does not work:
|
This is not going anywhere, let's close this |
Fix #15