c++ - pygtkscintilla auto indent -
i'm trying translate c++ code , can't work out "char linebuf[1000]" is, can kind sole translate python or explain linebuf is. thanks! :) taken 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'; (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))); } }
it buffer line of input text, of type char[1000]
, i.e. array of 1000 char
elements (which bytes, because c++ based upon c, in turn predates whole idea of character encodings).
if wanted literal translation of algorithm, closest fit in python array.array('b', [0]*1000)
. however, initializes python array, whereas c++ array uninitialized - there no way skip initialization in c++; reserves space without paying attention what's in chunk of memory.
Comments
Post a Comment