Ref T338, utility functions / parsing

- nthIndexOf
- measurement unit can be parsed case insensitive
- CSimpleCommandParser::remainingStringAfter from n-th space
- improved frequency parsing
This commit is contained in:
Klaus Basan
2018-09-08 02:11:03 +02:00
parent 3d2d999f7a
commit a9d728f451
7 changed files with 146 additions and 21 deletions

View File

@@ -395,6 +395,22 @@ namespace BlackMisc
if (question.endsWith("?")) { return question; }
return question % QStringLiteral("?");
}
int nthIndexOf(const QString &string, QChar ch, int nth, Qt::CaseSensitivity cs)
{
if (nth < 1 || string.isEmpty() || nth > string.length()) { return -1; }
int from = 0;
int ci = -1;
for (int t = 0; t < nth; ++t)
{
ci = string.indexOf(ch, from, cs);
if (ci < 0) { return -1; }
from = ci + 1;
if (from >= string.length()) { return -1; }
}
return ci;
}
} // ns
//! \endcond