I’m working on a Qt based software that involves some cryptography. The only three hashing algorithms used are specified as
SHA-256
MD5
SHA
However, the API that i am using requires them to be in the form of
sha256
md5
sha
respectively.
Even though I can write a messy function to somehow get things done, I know this can be simplified with the regular expression support in Qt. Please help me come up with a regular expression that does this task of conversion.
This is what I am doing now
if (hashType == QString("SHA")) {
return QString("sha");
}
else if (hashType == QString("MD5")) {
return QString("md5");
}
else if (hashType == QString("SHA-256")) {
return QString("sha256");
}
else {
return hashType;
}
I’d say using a regex is overkill for this. You just need: