summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstringalgorithms_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qstringalgorithms_p.h')
-rw-r--r--src/corelib/text/qstringalgorithms_p.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/corelib/text/qstringalgorithms_p.h b/src/corelib/text/qstringalgorithms_p.h
index 513e2b8cbc..f34acb01e8 100644
--- a/src/corelib/text/qstringalgorithms_p.h
+++ b/src/corelib/text/qstringalgorithms_p.h
@@ -47,26 +47,34 @@ template <typename StringType> struct QStringAlgorithms
static inline StringType trimmed_helper_inplace(const NakedStringType &, const Char *, const Char *)
{
// can't happen
- Q_UNREACHABLE();
- return StringType();
+ Q_UNREACHABLE_RETURN(StringType());
}
- static inline void trimmed_helper_positions(const Char *&begin, const Char *&end)
+ struct TrimPositions {
+ const Char *begin;
+ const Char *end;
+ };
+ // Returns {begin, end} where:
+ // - "begin" refers to the first non-space character
+ // - if there is a sequence of one or more space chacaters at the end,
+ // "end" refers to the first character in that sequence, otherwise
+ // "end" is str.cend()
+ [[nodiscard]] static TrimPositions trimmed_helper_positions(const StringType &str)
{
+ const Char *begin = str.cbegin();
+ const Char *end = str.cend();
// skip white space from end
while (begin < end && isSpace(end[-1]))
--end;
// skip white space from start
while (begin < end && isSpace(*begin))
begin++;
+ return {begin, end};
}
static inline StringType trimmed_helper(StringType &str)
{
- const Char *begin = str.cbegin();
- const Char *end = str.cend();
- trimmed_helper_positions(begin, end);
-
+ const auto [begin, end] = trimmed_helper_positions(str);
if (begin == str.cbegin() && end == str.cend())
return str;
if (!isConst && str.isDetached())