We have many many code snippet like below:
#if wxCHECK_VERSION(2, 9, 0)
Codef( _T("%AAppend(%t)"), ArrayChoices[i].wx_str());
#else
Codef( _T("%AAppend(%t)"), ArrayChoices[i].c_str());
#endif
I believe someone can create a simple find/replace script which can quickly replace those code snippet to:
Codef( _T("%AAppend(%t)"), ArrayChoices[i].wx_str());
Which tool can be used to do this? I found that manually delete those lines are some dirty work. ;)
EDIT:
The match condition should be:
#if wxCHECK_VERSION(2, 9, 0)
blablabla1
#else
blablabla2
#endif
The content of "blablabla1" and "blablabla2" should be the same only except the "wx_str" and "c_str".
Yes, replace in files with regex will do this
Make sure you have "use advanced regexes" checked in editor settings.
Link to syntax is in my sig. Use \n where n is an integer corresponding to your unnamed groups in the replace string. I never got around to adding support for substituting named groups in C::B (but maybe someone else did)
Something like this (untested)
#if WXCHECK_VERSION\(2\s*,9,\s*0\).*?\n(.*?)#else.*?#endif.*?\n
replace with
Edit: placement of spacing.
For some reason the ".*" doesn't operate through line endings (this may have been intentional), so I had to use this:
*#if wxCHECK_VERSION\(2\,\s*9\,\s*0\).*?\n(.*?)\n.*?#else\r?\n.*?\n.*?#endif(.*?)\n
replacing with
This allows at most one line of code between the #if, #else, and #endif lines.
OK, now the below regrex works(I did it under notepad++)
match:
\r\n[\t ]*#if wxCHECK_VERSION\(2\, 9\, 0\)\r\n([\t ]*.*?)wx_str(.*)\r\n[\t ]*#else\r\n(\1)c_str(\2)\r\n[\t ]*#endif
replace:
This only handle "one line" statement, I strip more than 200 places in our c::b source code, see the patches:
Any objection to apply this patch?
[attachment deleted by admin]
I see two kind of issues in wxsmith code:
Issue one:
#if wxCHECK_VERSION(2, 8, 0)
WX_DEFINE_ARRAY_INT(bool,wxArrayBool);
#else
WX_DEFINE_ARRAY(bool,wxArrayBool);
#endif
Can we just strip them to:
WX_DEFINE_ARRAY_INT(bool,wxArrayBool);
I think currently no one was using wx 2.7.x.
Issue two:
Still a lot of usage of c_str(), like:
Code = RebuildCode(BaseIndentation,Code.c_str(),(int)Code.Length(),EOL);
or
for ( const wxChar* Ch = Base.c_str(); *Ch; Ch++ )
Should they all convert to wx_str() ?