本文整理汇总了C++中Encoding::decode方法的典型用法代码示例。如果您正苦于以下问题:C++ Encoding::decode方法的具体用法?C++ Encoding::decode怎么用?C++ Encoding::decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoding
的用法示例。
在下文中一共展示了Encoding::decode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jsFromScriptFile
QString Utils::jsFromScriptFile(const QString& scriptPath, const Encoding& enc)
{
QFile jsFile(scriptPath);
if (jsFile.exists() && jsFile.open(QFile::ReadOnly)) {
QString scriptBody = enc.decode(jsFile.readAll());
// Remove CLI script heading
if (scriptBody.startsWith("#!") && !jsFile.fileName().endsWith(COFFEE_SCRIPT_EXTENSION)) {
scriptBody.prepend("//");
}
if (jsFile.fileName().endsWith(COFFEE_SCRIPT_EXTENSION)) {
QVariant result = Utils::coffee2js(scriptBody);
if (result.toStringList().at(0) == "false") {
return QString();
} else {
scriptBody = result.toStringList().at(1);
}
}
jsFile.close();
return scriptBody;
} else {
return QString();
}
}
示例2: jsFromScriptFile
static QString jsFromScriptFile(const QString& scriptPath, const QString& scriptLanguage, const Encoding& enc)
{
QFile jsFile(scriptPath);
if (jsFile.exists() && jsFile.open(QFile::ReadOnly)) {
QString scriptBody = enc.decode(jsFile.readAll());
jsFile.close();
// Remove CLI script heading
if (scriptBody.startsWith("#!")) {
int len = scriptBody.indexOf(QRegExp("[\r\n]"));
if (len == -1) {
len = scriptBody.length();
}
scriptBody.remove(0, len);
}
// If a language is specified and is not "javascript", reject it.
if (scriptLanguage != "javascript" && !scriptLanguage.isNull()) {
QString errMessage = QString("Unsupported language: %1").arg(scriptLanguage);
Terminal::instance()->cerr(errMessage);
qWarning("%s", qPrintable(errMessage));
return QString();
}
return scriptBody;
} else {
return QString();
}
}
示例3: injectJsInFrame
bool Utils::injectJsInFrame(const QString &jsFilePath, const Encoding &jsFileEnc, const QString &libraryPath, QWebFrame *targetFrame, const bool startingScript)
{
// Don't do anything if an empty string is passed
QFile jsFile(findScript(jsFilePath, libraryPath));
if (jsFile.exists() && jsFile.open(QFile::ReadOnly)) {
QString scriptBody = jsFileEnc.decode(jsFile.readAll());
// Remove CLI script heading
if (scriptBody.startsWith("#!") && !jsFile.fileName().endsWith(COFFEE_SCRIPT_EXTENSION)) {
scriptBody.prepend("//");
}
if (jsFile.fileName().endsWith(COFFEE_SCRIPT_EXTENSION)) {
QVariant result = Utils::coffee2js(scriptBody);
if (result.toStringList().at(0) == "false") {
if (startingScript) {
Terminal::instance()->cerr(result.toStringList().at(1));
exit(1);
} else {
qWarning() << qPrintable(result.toStringList().at(1));
scriptBody = QString();
}
} else {
scriptBody = result.toStringList().at(1);
}
}
// Execute JS code in the context of the document
targetFrame->evaluateJavaScript(scriptBody);
jsFile.close();
return true;
} else {
if (startingScript) {
Terminal::instance()->cerr(QString("Can't open '%1'").arg(jsFilePath));
} else {
qWarning("Can't open '%s'", qPrintable(jsFilePath));
}
}
return false;
}