Common: refactors number formatting to use type-specific append functions

This commit is contained in:
李通洲
2025-08-19 17:22:11 +08:00
parent 7f48500cfd
commit ec0fa89cc8
4 changed files with 29 additions and 11 deletions
+11 -3
View File
@@ -6,12 +6,20 @@ bool ffFreqAppendNum(uint32_t mhz, FFstrbuf* result)
return false;
const FFOptionsDisplay* options = &instance.config.display;
const char* space = options->freqSpaceBeforeUnit == FF_SPACE_BEFORE_UNIT_NEVER ? "" : " ";
bool spaceBeforeUnit = options->freqSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER;
int8_t ndigits = options->freqNdigits;
if (ndigits >= 0)
ffStrbufAppendF(result, "%.*f%sGHz", ndigits, mhz / 1000., space);
{
ffStrbufAppendDouble(result, mhz / 1000., ndigits);
if (spaceBeforeUnit) ffStrbufAppendC(result, ' ');
ffStrbufAppendS(result, "GHz");
}
else
ffStrbufAppendF(result, "%u%sMHz", (unsigned) mhz, space);
{
ffStrbufAppendUInt(result, mhz);
if (spaceBeforeUnit) ffStrbufAppendC(result, ' ');
ffStrbufAppendS(result, "MHz");
}
return true;
}
+1 -1
View File
@@ -52,7 +52,7 @@ static void* libraryLoad(const char* path, int maxVersion)
for(int i = maxVersion; i >= 0; --i)
{
uint32_t originalLength = pathbuf.length;
ffStrbufAppendF(&pathbuf, "%i", i);
ffStrbufAppendSInt(&pathbuf, i);
result = dlopen(pathbuf.chars, FF_DLOPEN_FLAGS);
if(result != NULL)
+11 -3
View File
@@ -50,13 +50,21 @@ int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2)
void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty)
{
if(version->major > 0 || version->minor > 0 || version->patch > 0)
ffStrbufAppendF(pretty, "%u", version->major);
{
ffStrbufAppendUInt(pretty, version->major);
}
if(version->minor > 0 || version->patch > 0)
ffStrbufAppendF(pretty, ".%u", version->minor);
{
ffStrbufAppendC(pretty, '.');
ffStrbufAppendUInt(pretty, version->minor);
}
if(version->patch > 0)
ffStrbufAppendF(pretty, ".%u", version->patch);
{
ffStrbufAppendC(pretty, '.');
ffStrbufAppendUInt(pretty, version->patch);
}
}
void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4)
+6 -4
View File
@@ -14,11 +14,13 @@ static void appendNum(FFstrbuf* result, uint64_t bytes, uint32_t base, const cha
counter++;
}
const char* space = options->sizeSpaceBeforeUnit == FF_SPACE_BEFORE_UNIT_NEVER ? "" : " ";
if(counter == 0)
ffStrbufAppendF(result, "%" PRIu64 "%s%s", bytes, space, prefixes[0]);
if (counter == 0)
ffStrbufAppendUInt(result, bytes);
else
ffStrbufAppendF(result, "%.*f%s%s", options->sizeNdigits, size, space, prefixes[counter]);
ffStrbufAppendDouble(result, size, (int8_t) options->sizeNdigits);
if (options->sizeSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER)
ffStrbufAppendC(result, ' ');
ffStrbufAppendS(result, prefixes[counter]);
}
void ffSizeAppendNum(uint64_t bytes, FFstrbuf* result)