3 ms·
grep /^unsafe(\s\{)|(\sfn)|(\strait)|(\simpl)/ Some variation of that, or four individual greps. I forgot how to use OR properly in Regex but each of those wor
by Nadya 10y ago
grep /^unsafe(\s\{)|(\sfn)|(\strait)|(\simpl)/
Some variation of that, or four individual greps. I forgot how to use OR properly in Regex but each of those works individually. Tested on regex101 [0] against the following code:
unsafe {
// Scary stuff...
}
unsafe trait Scary { }
unsafe impl Scary for i32 {}
unsafe fn danger_will_robinson() {
// Scary stuff...
}
That should catch all four instances that unsafe can be called in without any false positives. Since `fn`, `trait` and `impl` are keywords they won't change. Of course, any comments should be removed beforehand in case of a commented out unsafe block.
[0] https://regex101.com/ https://regex101.com/
- deleted 10y ago[deleted]
- Nadya 10y agoCleaned it up and tested it as Unit Tests. `^unsafe(\s(\{|fn|trait|impl))` will match the four examples I gave but not match print or commented `unsafe`. I'm not sure if unsafe can be indented inside of a block but ignoring whitespace at the start of a line should fix it. I did this as a learning experience because I either regex101 doesn't properly implement /g or I don't understand capture groups. :D [0] http://i.imgur.com/zMSVo4A.png http://i.imgur.com/zMSVo4A.png