c++ - pygtkscintilla 自动缩进

标签 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)));
     }
}

最佳答案

它是一行输入文本的缓冲区,类型为 char[1000],即 1000 个 char 元素的数组(实际上是 bytes ,因为 C++ 是基于 C 的,而 C 又早于字符编码的整个概念。

如果我们真的想要算法的直译,最接近 Python 的可能是 array.array('B', [0]*1000)。然而,这会初始化 Python 数组,而 C++ 数组是未初始化的——在 C++ 中确实没有办法跳过该初始化;它只是保留空间,而不关心那 block 内存中已经有什么。

关于c++ - pygtkscintilla 自动缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6769068/

相关文章:

c++ - 使用 bind 或 lambda 将 NULL 函数指针传递给类构造函数

c++ - 是否有 c++ 绑定(bind)可以跨 v8 和 JavaScriptCore?

Python scapy 导入错误

python - 搜索 pandas 数据框列,其输入值小于下一个索引列值

c++ - 如何正确关闭在 Glade 中创建的对话框?

c++ - 我可以在继承自 QObject 的同时使用 QSharedData 吗?

c++ - std::string 处理短字符串的性能

python - 特定模型的 Django 管理自定义模板

python - 如何启用/禁用工具栏项?

c - 错误 : unknown type name ‘GtkObject’