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".
Should be doable with regexes.
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
\1
Edit: placement of spacing.
Thanks!!
There are some answers, but I'm going to test under C::B's own editor right now.
how to use regex to strip the preprocessor directive (http://stackoverflow.com/questions/11826016/how-to-use-regex-to-strip-the-preprocessor-directive)
Edit:
It looks like the same regex replacement rule works under notepad++ does not work under c::b. :(
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
\1
This allows at most one line of code between the #if, #else, and #endif lines.
For what it's worth the patch to enable ".*" to match through newlines is pretty simple. Attached is an incomplete version (incomplete because it does not add UI to enabled/disable matching through newlines -- may actually be better to include the option in the editor dialog than the editor settings in any case.)
I wish you luck.
I also wish the patches had been accepted with the #else; since, it was not ever needed.
Tim S.
Quote from: stahta01 on August 06, 2012, 06:00:16 PM
it was not ever needed.
It
was needed (for a short period tough) when we were using an old wxWidgets 2.8.x version which did not have
wx_str(). I don't recall which that was, but IMHO we also sticked to this version with the whole core that time.
Quote from: MortenMacFly on August 06, 2012, 06:44:58 PM
Quote from: stahta01 on August 06, 2012, 06:00:16 PM
it was not ever needed.
It was needed (for a short period tough) when we were using an old wxWidgets 2.8.x version which did not have wx_str(). I don't recall which that was, but IMHO we also sticked to this version with the whole core that time.
If I see the wxWidgets logs correctly, wx_str() has returned exactly the same as c_str() for a real long time and has always been there in 2.8, but was not documented and included only for wx1.6 (!) compatibility.
The differences to c_str() have been intriduced with wx2.9.
But it is as it is, and changing it even manually is not too hard.
Quote from: jens on August 06, 2012, 07:11:53 PM
but was not documented and included only for wx1.6 (!) compatibility.
Al-right - didn't know that. I was always only looking at the official API (a.k.a CHM file). Well then - we are wx1.6 compatible, isn't it? ;D
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:
(\r\n)\1wx_str\2
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]
Quote from: ollydbg on August 07, 2012, 06:46:44 AM
Any objection to apply this patch?
Not from my side... I've removed some of these portions anyways already... Nice to see them all gone at once.
Ok, I have done in rev8202, and I think other parts of the preprocessor directives which can't matches by regex can be manually fixed later.
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() ?