Author Topic: Fix 'Tokenizer::FixArgument' bug: support skip C++ comment  (Read 6411 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Fix 'Tokenizer::FixArgument' bug: support skip C++ comment
« on: April 28, 2010, 05:33:51 am »
Code
Index: src/plugins/codecompletion/parser/tokenizer.cpp

===================================================================

--- src/plugins/codecompletion/parser/tokenizer.cpp (revision 6205)

+++ src/plugins/codecompletion/parser/tokenizer.cpp (working copy)

@@ -708,6 +708,16 @@

 
     TRACE(_T("FixArgument() : src='%s'."), src.wx_str());
 
+    // skip C++ comments
+    for (size_t i = 0; i < src.Length() - 1; ++i)
+    {
+        if (src.GetChar(i) == _T('/') && src.GetChar(i + 1) == _T('/'))
+        {
+            do src.SetChar(i, _T(' '));
+            while (src.GetChar(++i) != _T('\n') && i < src.Length() - 1);
+        }
+    }
+
     // str.Replace is massive overkill here since it has to allocate one new block per replacement
     { // this is much faster:
         size_t i;
Test Demo:
Code
void function ( int testInt1
//#ifdef AAA
, int testInt2)
//#else
//)
//#endif
{

};

void test(int testInt3
// test
          , int testInt4)
{
    testInt3
}

void ok(int testInt5 /*test*/, int testInt6)
{
    tes
}

Here is another test demo:
Code
#include <iostream>

using namespace std;

int test(int testInt1, // testijfiejfijeifje
         int testInt2, // fjiejifjfisjfif
         int testInt3)
{
    tes|
}

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}
« Last Edit: April 28, 2010, 07:04:09 am by Loaden »