MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey-v1.0 / VicinityToText

Method VicinityToText

Source/script.cpp:11417–11466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11415
11416
11417char *Line::VicinityToText(char *aBuf, size_t aBufSize, int aMaxLines)
11418// Translates the current line and the lines above and below it into their text equivalent
11419// putting the result into aBuf and returning the position in aBuf of its new string terminator.
11420{
11421 if (!aBuf || aBufSize < 256) return NULL;
11422
11423 char *aBuf_orig = aBuf;
11424
11425 if (aMaxLines < 5)
11426 aMaxLines = 5;
11427 --aMaxLines; // -1 to leave room for the current line itself.
11428
11429 int lines_following = (int)(aMaxLines / 2);
11430 int lines_preceding = aMaxLines - lines_following;
11431
11432 // Determine the correct value for line_start and line_end:
11433 int i;
11434 Line *line_start, *line_end;
11435 for (i = 0, line_start = this
11436 ; i < lines_preceding && line_start->mPrevLine != NULL
11437 ; ++i, line_start = line_start->mPrevLine);
11438
11439 for (i = 0, line_end = this
11440 ; i < lines_following && line_end->mNextLine != NULL
11441 ; ++i, line_end = line_end->mNextLine);
11442
11443 // Now line_start and line_end are the first and last lines of the range
11444 // we want to convert to text, and they're non-NULL.
11445 snprintf(aBuf, BUF_SPACE_REMAINING, "\tLine#\n");
11446 aBuf += strlen(aBuf);
11447
11448 size_t space_remaining;
11449
11450 // Start at the oldest and continue up through the newest:
11451 for (Line *line = line_start;;)
11452 {
11453 if (line == this)
11454 strlcpy(aBuf, "--->\t", BUF_SPACE_REMAINING);
11455 else
11456 strlcpy(aBuf, "\t", BUF_SPACE_REMAINING);
11457 aBuf += strlen(aBuf);
11458 space_remaining = BUF_SPACE_REMAINING; // Resolve macro only once for performance.
11459 // Truncate large lines so that the dialog is more readable:
11460 aBuf = line->ToText(aBuf, space_remaining < 500 ? space_remaining : 500, false);
11461 if (line == line_end)
11462 break;
11463 line = line->mNextLine;
11464 }
11465 return aBuf;
11466}
11467
11468
11469

Callers

nothing calls this directly

Calls 3

snprintfFunction · 0.85
strlcpyFunction · 0.85
ToTextMethod · 0.45

Tested by

no test coverage detected