StatusWith<std::unique_ptr<CollatorInterface>> CollatorFactoryICU::makeFromBSON( const BSONObj& spec) { // Parse the locale ID out of the spec. auto parsedLocaleID = parseLocaleID(spec); if (!parsedLocaleID.isOK()) { return parsedLocaleID.getStatus(); } // If spec = {locale: "simple"}, return a null pointer. A null CollatorInterface indicates // simple binary compare. if (parsedLocaleID.getValue() == CollationSpec::kSimpleBinaryComparison) { if (spec.nFields() > 1) { return {ErrorCodes::FailedToParse, str::stream() << "If locale=default, no other fields should be present in: " << spec}; } return {nullptr}; } // Check that the locale ID is recognizable by ICU. if (!isValidLocale(parsedLocaleID.getValue())) { return {ErrorCodes::BadValue, str::stream() << "Field '" << CollationSpec::kLocaleField << "' is not a valid ICU locale in: " << spec}; } // Construct an icu::Locale. auto locale = icu::Locale::createFromName(parsedLocaleID.getValue().c_str()); // Construct an icu::Collator. UErrorCode status = U_ZERO_ERROR; std::unique_ptr<icu::Collator> icuCollator(icu::Collator::createInstance(locale, status)); if (U_FAILURE(status)) { icu::ErrorCode icuError; icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to create collator: " << icuError.errorName() << ". Collation spec: " << spec}; } // Construct a CollationSpec using the options provided in spec or the defaults in icuCollator. // Use locale.getName() for the localeID, since it is canonicalized and includes options. auto parsedSpec = parseToCollationSpec(spec, locale.getName(), icuCollator.get()); if (!parsedSpec.isOK()) { return parsedSpec.getStatus(); } auto mongoCollator = stdx::make_unique<CollatorInterfaceICU>(std::move(parsedSpec.getValue()), std::move(icuCollator)); return {std::move(mongoCollator)}; }
int main(int argc, char* argv[]) { qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1"); MyApplication application(argc, argv); QFile f(QString("%1/style.css").arg(QCoreApplication::applicationDirPath())); if(f.open(QFile::ReadOnly | QFile::Text)) { QTextStream in(&f); auto style = in.readAll(); f.close(); application.setStyleSheet(style); } #if QT_VERSION < QT_VERSION_CHECK(5,0,0) QAbstractEventDispatcher::instance(application.thread())->setEventFilter(MyApplication::globalEventFilter); #else auto eventFilter = new MyEventFilter(); application.installNativeEventFilter(eventFilter); #endif // Get the hidden language setting (for testers) if(!BridgeSettingGet("Engine", "Language", currentLocale) || !isValidLocale(currentLocale)) { QStringList uiLanguages = QLocale::system().uiLanguages(); QString sysLocale = uiLanguages.size() ? QLocale(uiLanguages[0]).name() : QLocale::system().name(); strcpy_s(currentLocale, sysLocale.toUtf8().constData()); BridgeSettingSet("Engine", "Language", currentLocale); } // Load translations for Qt QTranslator qtTranslator; if(qtTranslator.load(QString("qt_%1").arg(currentLocale), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) application.installTranslator(&qtTranslator); //x64dbg and x32dbg can share the same translation QTranslator x64dbgTranslator; auto path = QString("%1/../translations").arg(QCoreApplication::applicationDirPath()); if(x64dbgTranslator.load(QString("x64dbg_%1").arg(currentLocale), path)) application.installTranslator(&x64dbgTranslator); TLS_TranslatedStringMap = new std::map<DWORD, TranslatedStringStorage>(); // initialize capstone Capstone::GlobalInitialize(); // load config file + set config font mConfiguration = new Configuration; application.setFont(ConfigFont("Application")); // Register custom data types qRegisterMetaType<dsint>("dsint"); qRegisterMetaType<duint>("duint"); qRegisterMetaType<byte_t>("byte_t"); qRegisterMetaType<DBGSTATE>("DBGSTATE"); // Set QString codec to UTF-8 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); #if QT_VERSION < QT_VERSION_CHECK(5,0,0) QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); #endif // Init communication with debugger Bridge::initBridge(); // Start GUI MainWindow* mainWindow; mainWindow = new MainWindow(); mainWindow->show(); // Set some data Bridge::getBridge()->winId = (void*)mainWindow->winId(); // Init debugger const char* errormsg = DbgInit(); if(errormsg) { QMessageBox msg(QMessageBox::Critical, QObject::tr("DbgInit Error!"), QString(errormsg)); msg.setWindowIcon(DIcon("compile-error.png")); msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint)); msg.exec(); exit(1); } //execute the application int result = application.exec(); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) application.removeNativeEventFilter(eventFilter); #else QAbstractEventDispatcher::instance(application.thread())->setEventFilter(nullptr); #endif delete mainWindow; mConfiguration->save(); //save config on exit { //delete tls auto temp = TLS_TranslatedStringMap; TLS_TranslatedStringMap = nullptr; delete temp; } //TODO free capstone/config/bridge and prevent use after free. return result; }