mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T323, functions to detect 0-9 chars since isDigit detects a lot of other chars
This commit is contained in:
@@ -21,7 +21,7 @@ namespace BlackMisc
|
||||
{
|
||||
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());
|
||||
if (s.isEmpty()) { return QString(); }
|
||||
if (s.contains(' '))
|
||||
{
|
||||
return s.left(s.indexOf(' '));
|
||||
}
|
||||
else
|
||||
{
|
||||
return s;
|
||||
}
|
||||
return s.contains(' ') ? s.left(s.indexOf(' ')) : s;
|
||||
}
|
||||
|
||||
QStringList simpleTextCodecNamesImpl()
|
||||
|
||||
@@ -114,6 +114,12 @@ namespace BlackMisc
|
||||
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
|
||||
inline const QString &safeAt(const QStringList &stringList, int index)
|
||||
{
|
||||
@@ -128,12 +134,36 @@ namespace BlackMisc
|
||||
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
|
||||
inline QString digitOnlyString(const QString &string)
|
||||
{
|
||||
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
|
||||
BLACKMISC_EXPORT const QString inApostrophes(const QString &in, bool ignoreEmpty = false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user