Skip to content

Commit

Permalink
Editor: optimize editor version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
apocelipes committed Oct 23, 2024
1 parent b577665 commit 65f6863
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/detection/editor/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,14 @@ const char* ffDetectEditor(FFEditorResult* result)
return NULL;

ffStrbufSubstrBeforeFirstC(&result->version, '\n');
for (uint32_t iStart = 0; iStart < result->version.length; ++iStart)
{
char c = result->version.chars[iStart];
if (ffCharIsDigit(c))
{
for (uint32_t iEnd = iStart + 1; iEnd < result->version.length; ++iEnd)
{
char c = result->version.chars[iEnd];
if (isspace(c))
{
ffStrbufSubstrBefore(&result->version, iEnd);
break;
}
}
if (iStart > 0)
ffStrbufSubstrAfter(&result->version, iStart - 1);
break;
}
const char* versionStart = strpbrk(result->version.chars, "0123456789");
if (versionStart != NULL) {
const char* versionEnd = strpbrk(versionStart, " \t\v\f");
if (versionEnd != NULL)
ffStrbufSubstrBefore(&result->version, (uint32_t)(versionEnd - result->version.chars));

if (versionStart != result->version.chars)
ffStrbufSubstrAfter(&result->version, (uint32_t)(versionStart - result->version.chars - 1));
}

return NULL;
Expand Down

0 comments on commit 65f6863

Please sign in to comment.