From 4615360c3a474bc0a3fa969267fb80c29af0ca5d Mon Sep 17 00:00:00 2001 From: zathras-crypto Date: Mon, 11 May 2015 21:07:23 -0700 Subject: [PATCH] UI: Add 'TruncateString' to override UI truncation if needed --- src/qt/omnicore_qtutils.cpp | 13 +++++++++++++ src/qt/omnicore_qtutils.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/qt/omnicore_qtutils.cpp b/src/qt/omnicore_qtutils.cpp index d1cff98526bb6..1ae1bcf4c9959 100644 --- a/src/qt/omnicore_qtutils.cpp +++ b/src/qt/omnicore_qtutils.cpp @@ -80,6 +80,19 @@ std::string StripTrailingZeros(const std::string& inputStr) return outputStr; } +/** + * Truncates a string at n digits and adds "..." to indicate that display is incomplete + */ +std::string TruncateString(const std::string& inputStr, unsigned int length) +{ + if (inputStr.empty()) return ""; + std::string outputStr = inputStr; + if (length > 0 && inputStr.length() > length) { + outputStr = inputStr.substr(0, length) + "..."; + } + return outputStr; +} + /** * Variable length find and replace. Find all iterations of findText within inputStr and replace them * with replaceText. diff --git a/src/qt/omnicore_qtutils.h b/src/qt/omnicore_qtutils.h index 143fbf2a765fd..e334e511a2037 100644 --- a/src/qt/omnicore_qtutils.h +++ b/src/qt/omnicore_qtutils.h @@ -11,6 +11,11 @@ namespace mastercore */ void PopulateSimpleDialog(const std::string& content, const std::string& title, const std::string& tooltip); + /** + * Truncates a string at n digits and adds "..." to indicate that display is incomplete + */ + std::string TruncateString(const std::string& inputStr, unsigned int length); + /** * Strips trailing zeros from a string containing a divisible value */