Merge pull request #632 from technomancy/fix-fennel-outline

Fix getFennelOutline.
This commit is contained in:
Vadim Grigoruk 2018-07-10 14:27:06 +03:00 committed by GitHub
commit 1298aadbdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 7 deletions

View File

@ -1680,28 +1680,36 @@ static const tic_outline_item* getFennelOutline(const char* code, s32* size)
while(true) while(true)
{ {
static const char FuncString[] = "fn"; /* this probably doesn't work */ static const char FuncString[] = "(fn ";
ptr = strstr(ptr, FuncString); ptr = strstr(ptr, FuncString);
if(ptr) if(ptr)
{ {
const char* end = ptr;
ptr += sizeof FuncString - 1; ptr += sizeof FuncString - 1;
while(end >= code && !isalnum_(*end)) end--; const char* start = ptr;
const char* end = start;
const char* start = end; while(*ptr)
{
char c = *ptr;
for (const char* val = start-1; val >= code && (isalnum_(*val)); val--, start--); if(c == ' ' || c == '\t' || c == '\n' || c == '[')
{
end = ptr;
break;
}
ptr++;
}
if(end > start) if(end > start)
{ {
items = items ? realloc(items, (*size + 1) * Size) : malloc(Size); items = items ? realloc(items, (*size + 1) * Size) : malloc(Size);
items[*size].pos = start - code; items[*size].pos = start - code;
items[*size].size = end - start + 1; items[*size].size = end - start;
(*size)++; (*size)++;
} }