Exemplo n.º 1
0
int Lexer::unicodeEscape()
{
    if (*idx == '{') {
        idx++;
        mark = idx;
        if (!hexDigits(-1) || *idx != '}')
            compiler->syntaxError(lineno, "Invalid variable-length unicode escape");
        int n = (int)parseInt(16);
        idx++;
        return n;
    }
    return hexEscape(4);
}
Exemplo n.º 2
0
static QString utf8encode(const QByteArray &array) // turns e.g. tranøy.no to tran\xc3\xb8y.no
{
    QString result;
    result.reserve(array.length() + array.length() / 3);
    for (int i = 0; i < array.length(); ++i) {
        char c = array.at(i);
        // if char is non-ascii, escape it
        if (c < 0x20 || uchar(c) >= 0x7f) {
            result += "\\x" + QString::number(uchar(c), 16);
        } else {
            // if previous char was escaped, we need to make sure the next char is not
            // interpreted as part of the hex value, e.g. "äc.com" -> "\xabc.com"; this
            // should be "\xab""c.com"
            QRegExp hexEscape("\\\\x[a-fA-F0-9][a-fA-F0-9]$");
            bool isHexChar = ((c >= '0' && c <= '9') ||
                             (c >= 'a' && c <= 'f') ||
                             (c >= 'A' && c <= 'F'));
            if (result.contains(hexEscape) && isHexChar)
                result += "\"\"";
            result += c;
        }
    }
    return result;
}
Exemplo n.º 3
0
int Lexer::escapeSequence()
{
    switch (*idx) {
    case  '0':
    case  '1':
    case  '2':
    case  '3':
    case  '4':
    case  '5':
    case  '6':
    case  '7':
        return octalOrNulEscape ();

    case 'x':
        idx++;
        // Compatibility fallback, handle \x<whatever> as "x" followed by <whatever>
        mark = idx;
        if (hexDigits(2)) {
            idx = mark;
            return hexEscape(2);
        }
        idx = mark;
        return 'x';

    case 'u':
        idx++;
        // Compatibility fallback, handle \u<whatever> as "u" followed by <whatever>
        mark = idx;
        if (hexDigits(4)) {
            idx = mark;
            return unicodeEscape ();
        }
        idx = mark;
        return 'u';

    case 'b':
        idx++;
        return '\b';

    case 'f':
        idx++;
        return '\f';

    case 'n':
        idx++;
        return '\n';

    case 'r':
        idx++;
        return '\r';

    case 't':
        idx++;
        return '\t';

    case 'v':
        idx++;
        return '\v';

    case  '\'':
    case  '"':
    case  '\\':
        return *idx++;

    case 0:
        if (idx+1 >= limit)
            compiler->syntaxError(lineno, "End of input in escape sequence");
        idx++;
        return 0;

    case     '\n':
    case     '\r':
    case UNICHAR_LS:
    case UNICHAR_PS:
        compiler->syntaxError(lineno, "Illegal line terminator in escape sequence");

    default:
        return *idx++;
    }
}