From 385a7b7b004b4b4ec71edc619cde4354bfdfa67c Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 18 Aug 2023 11:41:16 +0200 Subject: [PATCH] Added utility rstrip() to remove whitespace at the right end of a string. --- utils.cpp | 9 +++++++++ utils.h | 1 + 2 files changed, 10 insertions(+) diff --git a/utils.cpp b/utils.cpp index d17a7ea..92bf620 100644 --- a/utils.cpp +++ b/utils.cpp @@ -77,3 +77,12 @@ QString Utils::getTariffLoadTime(QString fileName) { return "N/A"; } +QString Utils::rstrip(QString const &str) { + int n = str.size() - 1; + for (; n >= 0; --n) { + if (!str.at(n).isSpace()) { + return str.left(n + 1); + } + } + return ""; +} diff --git a/utils.h b/utils.h index 86db3a6..79f838b 100644 --- a/utils.h +++ b/utils.h @@ -15,6 +15,7 @@ namespace Utils { void printInfoMsg(QString const &infoMsg); void printLineEditInfo(QStringList const &lines); QString getTariffLoadTime(QString fileName); + QString rstrip(QString const &str); } #endif // UTILS_H_INCLUDED