mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
CPU: remove duplicate whitespaces in CPU name
Eg. `Intel(R) Xeon(R) CPU E5620 @ 2.40GHz`
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user