Ref T323, functions to detect 0-9 chars since isDigit detects a lot of other chars

This commit is contained in:
Klaus Basan
2018-09-09 02:30:07 +02:00
parent 4b888d87f5
commit d60b900b84
2 changed files with 32 additions and 9 deletions

View File

@@ -21,7 +21,7 @@ namespace BlackMisc
{ {
return removeChars(s, [](QChar c) return removeChars(s, [](QChar c)
{ {
return c == ' ' || c == ':' || c == '_' || c == '-' || c == '.'; return c == u' ' || c == u':' || c == u'_' || c == u'-' || c == u'.';
}); });
} }
@@ -177,14 +177,7 @@ namespace BlackMisc
{ {
const QString s(candidate.trimmed().toUpper()); const QString s(candidate.trimmed().toUpper());
if (s.isEmpty()) { return QString(); } if (s.isEmpty()) { return QString(); }
if (s.contains(' ')) return s.contains(' ') ? s.left(s.indexOf(' ')) : s;
{
return s.left(s.indexOf(' '));
}
else
{
return s;
}
} }
QStringList simpleTextCodecNamesImpl() QStringList simpleTextCodecNamesImpl()

View File

@@ -114,6 +114,12 @@ namespace BlackMisc
return s.trimmed(); return s.trimmed();
} }
//! Is 0-9 char, isDigit allows a bunch of more characters
inline bool is09(const QChar &c) { return c >= u'0' && c <= u'9'; }
//! Is 0-9, or ","/";"
inline bool is09OrSeparator(const QChar &c) { return is09(c) || c == u',' || c == '.'; }
//! Safe "at" function, returns empty string if index does not exists //! Safe "at" function, returns empty string if index does not exists
inline const QString &safeAt(const QStringList &stringList, int index) inline const QString &safeAt(const QStringList &stringList, int index)
{ {
@@ -128,12 +134,36 @@ namespace BlackMisc
return !containsChar(testString, [](QChar c) { return !c.isDigit(); }); return !containsChar(testString, [](QChar c) { return !c.isDigit(); });
} }
//! String with 0-9 only
inline bool is09OnlyString(const QString &testString)
{
return !containsChar(testString, [](QChar c) { return !is09(c); });
}
//! String with 0-9/separator only
inline bool is09OrSeparatorOnlyString(const QString &testString)
{
return !containsChar(testString, [](QChar c) { return !is09OrSeparator(c); });
}
//! String only with digits //! String only with digits
inline QString digitOnlyString(const QString &string) inline QString digitOnlyString(const QString &string)
{ {
return removeChars(string, [](QChar c) { return !c.isDigit(); }); return removeChars(string, [](QChar c) { return !c.isDigit(); });
} }
//! String only with 0-9
inline QString char09OnlyString(const QString &string)
{
return removeChars(string, [](QChar c) { return !is09(c); });
}
//! String only with 0-9
inline QString char09OrSeparatorOnlyString(const QString &string)
{
return removeChars(string, [](QChar c) { return !is09OrSeparator(c); });
}
//! Return string in apostrophes //! Return string in apostrophes
BLACKMISC_EXPORT const QString inApostrophes(const QString &in, bool ignoreEmpty = false); BLACKMISC_EXPORT const QString inApostrophes(const QString &in, bool ignoreEmpty = false);