aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/string.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-04-13 14:05:03 +0200
committerGitHub Enterprise <[email protected]>2026-04-13 14:05:03 +0200
commitc49e5b15e0f86080d7d33e4e31aecfb701f8f96f (patch)
treeff41dcec20502c0cc4cf853222273f50d025cda3 /src/zencore/string.cpp
parentAdd MemoryCidStore and ChunkStore interface (#940) (diff)
downloadzen-c49e5b15e0f86080d7d33e4e31aecfb701f8f96f.tar.xz
zen-c49e5b15e0f86080d7d33e4e31aecfb701f8f96f.zip
Some minor polish from tourist branch (#949)
- Replace per-type fmt::formatter specializations (StringBuilderBase, NiceBase) with a single generic formatter using a HasStringViewConversion concept - Add ThousandsNum for comma-separated integer formatting (e.g. "1,234,567") - Thread naming now accepts a sort hint for trace ordering - Fix main thread trace registration to use actual thread ID and sort first - Add ExpandEnvironmentVariables() for expanding %VAR% references in strings, with tests - Add ParseHexBytes() overload with expected byte count validation - Add Flag_BelowNormalPriority to CreateProcOptions (BELOW_NORMAL_PRIORITY_CLASS on Windows, setpriority on POSIX) - Add PrettyScroll progress bar mode that pins the status line to the bottom of the terminal using scroll regions, with signal handler cleanup for Ctrl+C/SIGTERM
Diffstat (limited to 'src/zencore/string.cpp')
-rw-r--r--src/zencore/string.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/zencore/string.cpp b/src/zencore/string.cpp
index 358722b0b..df7d71250 100644
--- a/src/zencore/string.cpp
+++ b/src/zencore/string.cpp
@@ -381,6 +381,34 @@ NiceNumGeneral(uint64_t Num, std::span<char> Buffer, NicenumFormat Format)
}
size_t
+ThousandsToBuffer(uint64_t Num, std::span<char> Buffer)
+{
+ // Format into a temporary buffer without separators
+ char Tmp[24];
+ int Len = snprintf(Tmp, sizeof(Tmp), "%llu", (unsigned long long)Num);
+
+ // Insert comma separators
+ int SepCount = (Len - 1) / 3;
+ int TotalLen = Len + SepCount;
+ ZEN_ASSERT(TotalLen < (int)Buffer.size());
+
+ int Src = Len - 1;
+ int Dst = TotalLen;
+ Buffer[Dst--] = '\0';
+
+ for (int i = 0; Src >= 0; i++)
+ {
+ if (i > 0 && i % 3 == 0)
+ {
+ Buffer[Dst--] = ',';
+ }
+ Buffer[Dst--] = Tmp[Src--];
+ }
+
+ return TotalLen;
+}
+
+size_t
NiceNumToBuffer(uint64_t Num, std::span<char> Buffer)
{
return NiceNumGeneral(Num, Buffer, kNicenum1024);