mirror-chatterino2/src/util/IrcHelpers.hpp

62 lines
1.2 KiB
C++
Raw Normal View History

2017-12-17 00:01:42 +01:00
#pragma once
#include <QString>
namespace chatterino {
2018-06-04 12:23:23 +02:00
inline QString parseTagString(const QString &input)
2017-12-17 00:01:42 +01:00
{
QString output = input;
2017-12-17 00:39:27 +01:00
output.detach();
2017-12-17 00:01:42 +01:00
2018-06-05 16:29:06 +02:00
auto length = output.length();
2017-12-17 00:01:42 +01:00
2018-10-21 13:43:02 +02:00
for (int i = 0; i < length - 1; i++)
{
if (output[i] == '\\')
{
2017-12-17 00:39:27 +01:00
QChar c = output[i + 1];
2018-10-21 13:43:02 +02:00
switch (c.cell())
{
2019-09-26 00:51:05 +02:00
case 'n': {
2018-06-05 16:29:06 +02:00
output.replace(i, 2, '\n');
2018-10-21 13:43:02 +02:00
}
break;
2017-12-17 00:56:33 +01:00
2019-09-26 00:51:05 +02:00
case 'r': {
2018-06-05 16:29:06 +02:00
output.replace(i, 2, '\r');
2018-10-21 13:43:02 +02:00
}
break;
2017-12-17 00:56:33 +01:00
2019-09-26 00:51:05 +02:00
case 's': {
2018-06-05 16:29:06 +02:00
output.replace(i, 2, ' ');
2018-10-21 13:43:02 +02:00
}
break;
2017-12-17 00:56:33 +01:00
2019-09-26 00:51:05 +02:00
case '\\': {
2018-06-05 16:29:06 +02:00
output.replace(i, 2, '\\');
2018-10-21 13:43:02 +02:00
}
break;
2017-12-17 00:56:33 +01:00
2019-09-26 00:51:05 +02:00
case ':': {
2018-06-05 16:29:06 +02:00
output.replace(i, 2, ';');
2018-10-21 13:43:02 +02:00
}
break;
2017-12-17 00:56:33 +01:00
2019-09-26 00:51:05 +02:00
default: {
2018-06-05 16:29:06 +02:00
output.remove(i, 1);
2018-10-21 13:43:02 +02:00
}
break;
2017-12-17 00:39:27 +01:00
}
2017-12-17 00:56:33 +01:00
2017-12-17 00:39:27 +01:00
i++;
2018-06-05 16:29:06 +02:00
length--;
2017-12-17 00:39:27 +01:00
}
}
return output;
2017-12-17 00:01:42 +01:00
}
2017-12-17 00:01:42 +01:00
} // namespace chatterino