CPU: remove duplicate whitespaces in CPU name

Eg. `Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz`
This commit is contained in:
Carter Li
2024-11-26 16:35:33 +08:00
committed by Carter Li
parent 8b41cbd508
commit 9955e9da02
4 changed files with 52 additions and 0 deletions
+1
View File
@@ -16,6 +16,7 @@ const char* ffDetectCPU(const FFCPUOptions* options, FFCPUResult* cpu)
ffStrbufRemoveStrings(&cpu->name, ARRAY_SIZE(removeStrings), removeStrings);
ffStrbufSubstrBeforeFirstC(&cpu->name, '@'); //Cut the speed output in the name as we append our own
ffStrbufTrimRight(&cpu->name, ' '); //If we removed the @ in previous step there was most likely a space before it
ffStrbufRemoveDupWhitespaces(&cpu->name);
return NULL;
}
+22
View File
@@ -575,3 +575,25 @@ bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer)
*n = remaining;
return true;
}
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf)
{
if (strbuf->allocated == 0) return false; // Doesn't work with static strings
bool changed = false;
for (uint32_t i = 0; i < strbuf->length; i++)
{
if (strbuf->chars[i] != ' ') continue;
i++;
uint32_t j = i;
for (; j < strbuf->length && strbuf->chars[j] == ' '; j++);
if (j == i) continue;
memmove(&strbuf->chars[i], &strbuf->chars[j], strbuf->length - j + 1);
strbuf->length -= j - i;
changed = true;
}
return changed;
}
+1
View File
@@ -91,6 +91,7 @@ void ffStrbufUpperCase(FFstrbuf* strbuf);
void ffStrbufLowerCase(FFstrbuf* strbuf);
bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer);
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf);
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate)
{