Разница незначительна, когда код выполняется на самом деле, но при кодировании я обнаружил, что ввод скобок: (1): быстрее, (2): более условно и (3): позволяет меньше шансов на ошибку (конец) кто-нибудь?).
В качестве бонуса редактор, который я использую, автоматически форматирует циклы while (со скобками, по умолчанию) и в будущем, если что-то не так, встроенная функция сопоставления скобок поймает его.
Is there a simple regex to match a C++ function? No.
Is there a (complex) regex to match a C++. Maybe or could be possible to write one.
But I would say regular expressions neither are easily up to such a task (given you want some kind of excat match) nor are they the right tool for such a task.
Just think about case like this one. How would you handle this stuff.
void (*function(int, void (*)(int)))(int);
func1(int), func2(double); double func3(int);
The only real solution is to use a parser using yacc/lex. Which for your use case of course does nothing.
So either hack together some incomplete regex which fits most functions signatures in your code
Если вы собираетесь применять это только к вашим коммитам, я бы рекомендовал выработать привычку добавлять комментарий коммита к функции, например:
void something ()
{
...
some thing = 1;
...
}
to
void something ()
// last change by me: a better value for thing
{
...
some thing = 2;
...
}
отобразит для вас функцию и ваш комментарий с изменениями. В качестве бонуса другие люди смогут понять, что вы делаете.
TortoiseSVN использует следующие регулярные выражения для поддержки автозаполнения в диалоге фиксации для файлов C ++:
.h, .hpp, .hxx = ^\s*(?:class|struct)\s+([\w_]+)|\W([\w_]+)\(
.cpp, .c, .cxx = \W(([\w_]+)::([\w_]+))|\W([\w_]+)\(
Я не знаю Однако не знаю, насколько они точны.
I don't know of an option in SVN that will do this, and a regex-based solution will likely be one or more of the following:
You need some sort of parser for this. It's technically possible to enumerate all of the possible regex cases, but writing a parser is the correct way to solve this. If you have time to roll your own solution I'd check out ANTLR, they have several C/C++ grammars available on this page: