【问题标题】:pygtkscintilla auto indentpygtkscintilla 自动缩进
【发布时间】:2011-07-20 21:59:15
【问题描述】:

我正在尝试翻译 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)));
     }
}

【问题讨论】:

  • 你想不出一个简单的类型声明,但其余的都没有问题?真的吗?
  • @Karl Knechtel 是的 :)

标签: c++ python gtk pygtk scintilla


【解决方案1】:

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

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

【讨论】:

  • 知道如何从 pygtkscintilla 获得这个吗? Edit 如果我问什么是等价的可能会更好,为什么 linebuf 在那里?是为了这个职位吗?
  • 什么意思?它是一行文本的缓冲区。它保存来自编辑器的文本副本,以便可以对其进行修改然后反馈。看起来SendEditor 函数用于与编辑器进行通信。我什至无法理解你所说的“是为了这个职位吗?”。
  • 感谢您的解释,我已经知道 SendEditor,但不明白缓冲区的用途。谢谢你的解释!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 2010-09-29
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多