// DragonX Wallet - ImGui Edition // Copyright 2024-2026 The Hush Developers // Released under the GPLv3 // // Small shared text helpers used across the immediate-mode UI. Centralised here so the per-frame // hot paths use one allocation-free implementation instead of several copies. #pragma once #include #include #include namespace dragonx { namespace util { // Localized relative time, e.g. "5 minutes ago" (via i18n). Empty when timestamp <= 0. std::string formatTimeAgo(std::int64_t timestamp); // Compact, non-localized relative time for tight UI: "5s ago" / "3m ago" / "2h ago" / "4d ago". std::string formatTimeAgoShort(std::int64_t timestamp); // Case-insensitive substring test that does NOT allocate (unlike lower-casing copies + find). // An empty needle matches everything. Safe for per-frame filtering of large lists. bool containsIgnoreCase(std::string_view haystack, std::string_view needle); // Middle-ellipsis truncation, half/half form: "prefix...suffix" so the total (including "...") // is at most maxLen. Guards maxLen <= 3 (returns s unchanged) to avoid unsigned underflow on the // (maxLen - 3) split. Strings already at/under maxLen are returned unchanged. std::string truncateMiddle(const std::string& s, int maxLen); // Middle-ellipsis truncation with explicit prefix/suffix lengths: "...". // Returns s unchanged when it is no longer than front + back + 3 (the "..." would not save space). std::string truncateMiddle(const std::string& s, int front, int back); } // namespace util } // namespace dragonx