MCPcopy Create free account
hub / github.com/bumptop/BumpTop / transcode

Function transcode

trunk/win/Source/LUpdateString/cpp.cpp:676–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

674
675
676static QString transcode(const QString &str, bool utf8)
677{
678 static const char tab[] = "abfnrtv";
679 static const char backTab[] = "\a\b\f\n\r\t\v";
680 const QString in = (!utf8 || yySourceIsUnicode)
681 ? str : QString::fromUtf8(yySourceCodec->fromUnicode(str).data());
682 QString out;
683
684 out.reserve(in.length());
685 for (int i = 0; i < in.length();) {
686 ushort c = in[i++].unicode();
687 if (c == '\\') {
688 if (i >= in.length())
689 break;
690 c = in[i++].unicode();
691
692 if (c == '\n')
693 continue;
694
695 if (c == 'x') {
696 QByteArray hex;
697 while (i < in.length() && isxdigit((c = in[i].unicode()))) {
698 hex += c;
699 i++;
700 }
701 out += hex.toUInt(0, 16);
702 } else if (c >= '0' && c < '8') {
703 QByteArray oct;
704 int n = 0;
705 oct += c;
706 while (n < 2 && i < in.length() && (c = in[i].unicode()) >= '0' && c < '8') {
707 i++;
708 n++;
709 oct += c;
710 }
711 out += oct.toUInt(0, 8);
712 } else {
713 const char *p = strchr(tab, c);
714 out += QChar(QLatin1Char(!p ? c : backTab[p - tab]));
715 }
716 } else {
717 out += c;
718 }
719 }
720 return out;
721}
722
723static void recordMessage(
724 Translator *tor, int line, const QString &context, const QString &text, const QString &comment,

Callers 1

recordMessageFunction · 0.85

Calls 6

QLatin1CharClass · 0.85
QCharFunction · 0.50
dataMethod · 0.45
reserveMethod · 0.45
lengthMethod · 0.45
unicodeMethod · 0.45

Tested by

no test coverage detected