⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qscriptecmaglobal.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtScript module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/// for strtoll#include <qplatformdefs.h>#ifndef QT_NO_SCRIPT#include "qscriptecmaglobal_p.h"#include "qscriptengine_p.h"#include "qscriptvalueimpl_p.h"#include "qscriptcontext_p.h"#include "qscriptmember_p.h"#include "qscriptobject_p.h"#include <QtCore/QVarLengthArray>#include <QtCore/qnumeric.h>extern Q_CORE_EXPORT qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok);static inline char toHex(char c){    static const char hexnumbers[] = "0123456789ABCDEF";    return hexnumbers[c & 0xf];}static int fromHex(char c){    if ((c >= '0') && (c <= '9'))        return c - '0';    if ((c >= 'A') && (c <= 'F'))        return c - 'A' + 10;    if ((c >= 'a') && (c <= 'f'))        return c - 'a' + 10;    return -1;}static QByteArray escape(const QString &input){    QVarLengthArray<char> output;    output.reserve(input.size() * 3);    const int length = input.length();    for (int i = 0; i < length; ++i) {        ushort uc = input.at(i).unicode();        if (uc < 0x100) {            if (   (uc > 0x60 && uc < 0x7B)                || (uc > 0x3F && uc < 0x5B)                || (uc > 0x2C && uc < 0x3A)                || (uc == 0x2A)                || (uc == 0x2B)                || (uc == 0x5F)) {                output.append(char(uc));            } else {                output.append('%');                output.append(toHex(uc >> 4));                output.append(toHex(uc));            }        } else {            output.append('%');            output.append('u');            output.append(toHex(uc >> 12));            output.append(toHex(uc >> 8));            output.append(toHex(uc >> 4));            output.append(toHex(uc));        }    }    return QByteArray(output.constData(), output.size());}static QString unescape(const QByteArray &input){    QString result;    int i = 0;    const int length = input.length();    while (i < length) {        char c = input.at(i++);        if ((c == '%') && (i + 1 < length)) {            char a = input.at(i);            if ((a == 'u') && (i + 4 < length)) {                int d3 = fromHex(input.at(i+1));                int d2 = fromHex(input.at(i+2));                int d1 = fromHex(input.at(i+3));                int d0 = fromHex(input.at(i+4));                if ((d3 != -1) && (d2 != -1) && (d1 != -1) && (d0 != -1)) {                    ushort uc = ushort((d3 << 12) | (d2 << 8) | (d1 << 4) | d0);                    result.append(QChar(uc));                    i += 5;                } else {                    result.append(QLatin1Char(c));                }            } else {                int d1 = fromHex(a);                int d0 = fromHex(input.at(i+1));                if ((d1 != -1) && (d0 != -1)) {                    c = (d1 << 4) | d0;                    i += 2;                }                result.append(QLatin1Char(c));            }        } else {            result.append(QLatin1Char(c));        }    }    return result;}static const char uriReserved[] = ";/?:@&=+$,";static const char uriUnescaped[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()";static QString encode(const QString &input, const QString &unescapedSet, bool *ok){    QString output;    const int length = input.length();    int i = 0;    while (i < length) {        const QChar c = input.at(i);        if (!unescapedSet.contains(c)) {            ushort uc = c.unicode();            if ((uc >= 0xDC00) && (uc <= 0xDFFF)) {                // URIError                break;            }            if (!((uc < 0xD800) || (uc > 0xDBFF))) {                ++i;                if (i == length) {                    // URIError                    break;                }                const ushort uc2 = input.at(i).unicode();                if ((uc < 0xDC00) || (uc > 0xDFFF)) {                    // URIError                    break;                }                uc = ((uc - 0xD800) * 0x400) + (uc2 - 0xDC00) + 0x10000;            }            QString tmp(1, QChar(uc));            QByteArray octets = tmp.toUtf8();            for (int j = 0; j < octets.length(); ++j) {                output.append(QLatin1Char('%'));                output.append(QLatin1Char(toHex(octets.at(j) >> 4)));                output.append(QLatin1Char(toHex(octets.at(j))));            }        } else {            output.append(c);        }        ++i;    }    *ok = (i == length);    return output;}static QString decode(const QString &input, const QString &reservedSet, bool *ok){    QString output;    const int length = input.length();    int i = 0;    const QChar percent = QLatin1Char('%');    while (i < length) {        const QChar c = input.at(i);        if (c == percent) {            int start = i;            if (i + 2 >= length) {                // URIError                break;            }            int d1 = fromHex(input.at(i+1).toLatin1());            int d0 = fromHex(input.at(i+2).toLatin1());            if ((d1 == -1) || (d0 == -1)) {                // URIError                break;            }            int b = (d1 << 4) | d0;            i += 2;            if (b & 0x80) {                int n = -1;                while ((b << ++n) & 0x80) ;                if ((n == 1) || (n > 4)) {                    // URIError                    break;                }                QByteArray octets;                octets.append(b);                if (i + (3 * (n - 1)) >= length) {                    // URIError                    break;                }                for (int j = 1; j < n; ++j) {                    ++i;                    if (input.at(i) != percent) {                        // URIError                        break;                    }                    d1 = fromHex(input.at(i+1).toLatin1());                    d0 = fromHex(input.at(i+2).toLatin1());                    if ((d1 == -1) || (d0 == -1)) {                        // URIError                        break;                    }                    b = (d1 << 4) | d0;                    if ((b & 0xC0) != 0x80) {                        // URIError                        break;                    }                    i += 2;                    octets.append(b);                }                QString tmp = QString::fromUtf8(octets);                Q_ASSERT(tmp.length() == 1);                uint v = tmp.at(0).unicode(); // ### need 32-bit value                if (v < 0x10000) {                    QChar z = QChar(ushort(v));                    if (!reservedSet.contains(z)) {                        output.append(z);                    } else {                        output.append(input.mid(start, i - start + 1));                    }                } else {                    if (v > 0x10FFFF) {                        // URIError                        break;                    }                    ushort l = ushort(((v - 0x10000) & 0x3FF) + 0xDC00);                    ushort h = ushort((((v - 0x10000) >> 10) & 0x3FF) + 0xD800);                    output.append(QChar(l));                    output.append(QChar(h));                }            } else {                output.append(ushort(b));            }        } else {            output.append(c);        }        ++i;    }    *ok = (i == length);    return output;}namespace QScript {class PrintFunction : public QScriptFunction{public:    PrintFunction():        qout(stdout, QIODevice::WriteOnly) {}    virtual ~PrintFunction() {}    virtual void execute(QScriptContextPrivate *context)    {        QScriptEnginePrivate *eng = context->enginePrivate();        for (int i = 0; i < context->argumentCount(); ++i) {            if (i != 0)                qout << QLatin1String(" ");            qout << context->argument(i).toString();        }        qout << endl;        context->setReturnValue(eng->undefinedValue());    }    QTextStream qout;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -