pygtkscintilla auto indent

时间:2011-07-20 21:59:15

标签: c++ python gtk pygtk scintilla

我正在尝试翻译c ++代码而我无法弄清楚“char linebuf [1000]”是什么,可以将其转换为python或解释什么是linebuf。谢谢! :)取自http://www.scintilla.org/ScintillaUsage.html

if  (ch  ==  '\r'  ||  ch  ==  '\n')  {
     char  linebuf[1000];
     int  curLine  =  GetCurrentLineNumber();
     int  lineLength  =  SendEditor(SCI_LINELENGTH,  curLine);
     //Platform::DebugPrintf("[CR] %d len = %d\n", curLine, lineLength);
     if  (curLine  >  0  &&  lineLength  <=  2)  {
     int  prevLineLength  =  SendEditor(SCI_LINELENGTH,  curLine  -  1);
     if  (prevLineLength  <  sizeof(linebuf))  {
         WORD  buflen  =  sizeof(linebuf);
         memcpy(linebuf,  &buflen,  sizeof(buflen));
         SendEditor(EM_GETLINE,  curLine  -  1,
                    reinterpret_cast<LPARAM>(static_cast<char  *>(linebuf)));
         linebuf[prevLineLength]  =  '\0';
         for  (int  pos  =  0;  linebuf[pos];  pos++)  {
             if  (linebuf[pos]  !=  ' '  &&  linebuf[pos]  !=  '\t')
                 linebuf[pos]  =  '\0';
         }
         SendEditor(EM_REPLACESEL,  0,  reinterpret_cast<LPARAM>(static_cast<char  *>(linebuf)));
     }
}

1 个答案:

答案 0 :(得分:0)

它是一行char[1000]类型的输入文本的缓冲区,即1000 char个元素的数组(实际上是字节,因为C ++是基于的在C上,这反过来早于字符编码的整个想法。)

如果我们真的想要算法的字面翻译,那么Python中最接近的拟合可能就像array.array('B', [0]*1000)。但是,这会初始化Python数组,而C ++数组是未初始化的 - 实际上没有办法在C ++中跳过初始化;它只是保留了空间,而没有注意那段记忆中已有的东西。