mirror of
https://github.com/tnodir/fort
synced 2024-11-15 04:05:50 +00:00
UI: StringUtil: Add serviceSid()
This commit is contained in:
parent
d7371217d2
commit
5d191824bc
@ -9,17 +9,30 @@ QString StringUtil::capitalize(const QString &text)
|
|||||||
return firstChar.toUpper() + text.mid(1);
|
return firstChar.toUpper() + text.mid(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray StringUtil::cryptoSha1(const QByteArray &data)
|
||||||
|
{
|
||||||
|
return QCryptographicHash::hash(data, QCryptographicHash::Sha1);
|
||||||
|
}
|
||||||
|
|
||||||
QString StringUtil::cryptoHash(const QString &text)
|
QString StringUtil::cryptoHash(const QString &text)
|
||||||
{
|
{
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
const QByteArray data = text.toUtf8();
|
const QByteArray data = text.toUtf8();
|
||||||
const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Sha1);
|
const QByteArray hash = cryptoSha1(data);
|
||||||
|
|
||||||
return QString::fromLatin1(hash.toHex());
|
return QString::fromLatin1(hash.toHex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray StringUtil::serviceSid(const QString &serviceName)
|
||||||
|
{
|
||||||
|
const auto name = serviceName.toUpper();
|
||||||
|
const QByteArray nameData((const char *) name.utf16(), name.size() * sizeof(wchar_t));
|
||||||
|
|
||||||
|
return StringUtil::cryptoSha1(nameData);
|
||||||
|
}
|
||||||
|
|
||||||
int StringUtil::lineStart(const QString &text, int pos, int badPos)
|
int StringUtil::lineStart(const QString &text, int pos, int badPos)
|
||||||
{
|
{
|
||||||
const int startPos = text.lastIndexOf(QLatin1Char('\n'), pos);
|
const int startPos = text.lastIndexOf(QLatin1Char('\n'), pos);
|
||||||
|
@ -11,8 +11,11 @@ class StringUtil
|
|||||||
public:
|
public:
|
||||||
static QString capitalize(const QString &text);
|
static QString capitalize(const QString &text);
|
||||||
|
|
||||||
|
static QByteArray cryptoSha1(const QByteArray &data);
|
||||||
static QString cryptoHash(const QString &text);
|
static QString cryptoHash(const QString &text);
|
||||||
|
|
||||||
|
static QByteArray serviceSid(const QString &serviceName);
|
||||||
|
|
||||||
static int lineStart(const QString &text, int pos, int badPos = -1);
|
static int lineStart(const QString &text, int pos, int badPos = -1);
|
||||||
static int lineEnd(const QString &text, int pos, int badPos = -1);
|
static int lineEnd(const QString &text, int pos, int badPos = -1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user