Skip to content

Commit ec0fa89

Browse files
committed
Common: refactors number formatting to use type-specific append functions
1 parent 7f48500 commit ec0fa89

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

src/common/frequency.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ bool ffFreqAppendNum(uint32_t mhz, FFstrbuf* result)
66
return false;
77

88
const FFOptionsDisplay* options = &instance.config.display;
9-
const char* space = options->freqSpaceBeforeUnit == FF_SPACE_BEFORE_UNIT_NEVER ? "" : " ";
9+
bool spaceBeforeUnit = options->freqSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER;
1010
int8_t ndigits = options->freqNdigits;
1111

1212
if (ndigits >= 0)
13-
ffStrbufAppendF(result, "%.*f%sGHz", ndigits, mhz / 1000., space);
13+
{
14+
ffStrbufAppendDouble(result, mhz / 1000., ndigits);
15+
if (spaceBeforeUnit) ffStrbufAppendC(result, ' ');
16+
ffStrbufAppendS(result, "GHz");
17+
}
1418
else
15-
ffStrbufAppendF(result, "%u%sMHz", (unsigned) mhz, space);
19+
{
20+
ffStrbufAppendUInt(result, mhz);
21+
if (spaceBeforeUnit) ffStrbufAppendC(result, ' ');
22+
ffStrbufAppendS(result, "MHz");
23+
}
1624
return true;
1725
}

src/common/library.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void* libraryLoad(const char* path, int maxVersion)
5252
for(int i = maxVersion; i >= 0; --i)
5353
{
5454
uint32_t originalLength = pathbuf.length;
55-
ffStrbufAppendF(&pathbuf, "%i", i);
55+
ffStrbufAppendSInt(&pathbuf, i);
5656

5757
result = dlopen(pathbuf.chars, FF_DLOPEN_FLAGS);
5858
if(result != NULL)

src/common/parsing.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2)
5050
void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty)
5151
{
5252
if(version->major > 0 || version->minor > 0 || version->patch > 0)
53-
ffStrbufAppendF(pretty, "%u", version->major);
53+
{
54+
ffStrbufAppendUInt(pretty, version->major);
55+
}
5456

5557
if(version->minor > 0 || version->patch > 0)
56-
ffStrbufAppendF(pretty, ".%u", version->minor);
58+
{
59+
ffStrbufAppendC(pretty, '.');
60+
ffStrbufAppendUInt(pretty, version->minor);
61+
}
5762

5863
if(version->patch > 0)
59-
ffStrbufAppendF(pretty, ".%u", version->patch);
64+
{
65+
ffStrbufAppendC(pretty, '.');
66+
ffStrbufAppendUInt(pretty, version->patch);
67+
}
6068
}
6169

6270
void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4)

src/common/size.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ static void appendNum(FFstrbuf* result, uint64_t bytes, uint32_t base, const cha
1414
counter++;
1515
}
1616

17-
const char* space = options->sizeSpaceBeforeUnit == FF_SPACE_BEFORE_UNIT_NEVER ? "" : " ";
18-
if(counter == 0)
19-
ffStrbufAppendF(result, "%" PRIu64 "%s%s", bytes, space, prefixes[0]);
17+
if (counter == 0)
18+
ffStrbufAppendUInt(result, bytes);
2019
else
21-
ffStrbufAppendF(result, "%.*f%s%s", options->sizeNdigits, size, space, prefixes[counter]);
20+
ffStrbufAppendDouble(result, size, (int8_t) options->sizeNdigits);
21+
if (options->sizeSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER)
22+
ffStrbufAppendC(result, ' ');
23+
ffStrbufAppendS(result, prefixes[counter]);
2224
}
2325

2426
void ffSizeAppendNum(uint64_t bytes, FFstrbuf* result)

0 commit comments

Comments
 (0)