App: Avoid C string compare
Since we are linking to boost anyway, use boost function for case insensitive string compare. While there, make affected methods accept std::string arguments, which simplifies code a bit.
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
# define WINVER 0x502 // needed for SetDllDirectory
|
||||
# include <Windows.h>
|
||||
# endif
|
||||
# include <boost/algorithm/string.hpp>
|
||||
# include <boost/program_options.hpp>
|
||||
# include <boost/date_time/posix_time/posix_time.hpp>
|
||||
# include <boost/scope_exit.hpp>
|
||||
@@ -1339,18 +1340,15 @@ void Application::changeImportModule(const char* filter, const char* oldModuleNa
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> Application::getImportModules(const char* extension) const
|
||||
std::vector<std::string> Application::getImportModules(const std::string& extension) const
|
||||
{
|
||||
std::vector<std::string> modules;
|
||||
for (const auto & it : _mImportTypes) {
|
||||
const std::vector<std::string>& types = it.types;
|
||||
for (const auto & jt : types) {
|
||||
#ifdef __GNUC__
|
||||
if (strcasecmp(extension, jt.c_str()) == 0)
|
||||
#else
|
||||
if (_stricmp(extension, jt.c_str()) == 0)
|
||||
#endif
|
||||
if (boost::iequals(extension, jt)) {
|
||||
modules.push_back(it.module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1369,16 +1367,13 @@ std::vector<std::string> Application::getImportModules() const
|
||||
return modules;
|
||||
}
|
||||
|
||||
std::vector<std::string> Application::getImportTypes(const char* Module) const
|
||||
std::vector<std::string> Application::getImportTypes(const std::string& Module) const
|
||||
{
|
||||
std::vector<std::string> types;
|
||||
for (const auto & it : _mImportTypes) {
|
||||
#ifdef __GNUC__
|
||||
if (strcasecmp(Module,it.module.c_str()) == 0)
|
||||
#else
|
||||
if (_stricmp(Module,it.module.c_str()) == 0)
|
||||
#endif
|
||||
if (boost::iequals(Module, it.module)) {
|
||||
types.insert(types.end(), it.types.begin(), it.types.end());
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
@@ -1397,18 +1392,15 @@ std::vector<std::string> Application::getImportTypes() const
|
||||
return types;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> Application::getImportFilters(const char* extension) const
|
||||
std::map<std::string, std::string> Application::getImportFilters(const std::string& extension) const
|
||||
{
|
||||
std::map<std::string, std::string> moduleFilter;
|
||||
for (const auto & it : _mImportTypes) {
|
||||
const std::vector<std::string>& types = it.types;
|
||||
for (const auto & jt : types) {
|
||||
#ifdef __GNUC__
|
||||
if (strcasecmp(extension,jt.c_str()) == 0)
|
||||
#else
|
||||
if (_stricmp(extension,jt.c_str()) == 0)
|
||||
#endif
|
||||
if (boost::iequals(extension, jt)) {
|
||||
moduleFilter[it.filter] = it.module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1464,18 +1456,15 @@ void Application::changeExportModule(const char* filter, const char* oldModuleNa
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> Application::getExportModules(const char* extension) const
|
||||
std::vector<std::string> Application::getExportModules(const std::string& extension) const
|
||||
{
|
||||
std::vector<std::string> modules;
|
||||
for (const auto & it : _mExportTypes) {
|
||||
const std::vector<std::string>& types = it.types;
|
||||
for (const auto & jt : types) {
|
||||
#ifdef __GNUC__
|
||||
if (strcasecmp(extension,jt.c_str()) == 0)
|
||||
#else
|
||||
if (_stricmp(extension,jt.c_str()) == 0)
|
||||
#endif
|
||||
if (boost::iequals(extension, jt)) {
|
||||
modules.push_back(it.module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1494,16 +1483,13 @@ std::vector<std::string> Application::getExportModules() const
|
||||
return modules;
|
||||
}
|
||||
|
||||
std::vector<std::string> Application::getExportTypes(const char* Module) const
|
||||
std::vector<std::string> Application::getExportTypes(const std::string& Module) const
|
||||
{
|
||||
std::vector<std::string> types;
|
||||
for (const auto & it : _mExportTypes) {
|
||||
#ifdef __GNUC__
|
||||
if (strcasecmp(Module,it.module.c_str()) == 0)
|
||||
#else
|
||||
if (_stricmp(Module,it.module.c_str()) == 0)
|
||||
#endif
|
||||
if (boost::iequals(Module, it.module)) {
|
||||
types.insert(types.end(), it.types.begin(), it.types.end());
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
@@ -1522,18 +1508,15 @@ std::vector<std::string> Application::getExportTypes() const
|
||||
return types;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> Application::getExportFilters(const char* extension) const
|
||||
std::map<std::string, std::string> Application::getExportFilters(const std::string& extension) const
|
||||
{
|
||||
std::map<std::string, std::string> moduleFilter;
|
||||
for (const auto & it : _mExportTypes) {
|
||||
const std::vector<std::string>& types = it.types;
|
||||
for (const auto & jt : types) {
|
||||
#ifdef __GNUC__
|
||||
if (strcasecmp(extension,jt.c_str()) == 0)
|
||||
#else
|
||||
if (_stricmp(extension,jt.c_str()) == 0)
|
||||
#endif
|
||||
if (boost::iequals(extension, jt)) {
|
||||
moduleFilter[it.filter] = it.module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2847,8 +2830,7 @@ std::list<std::string> Application::processFiles(const std::list<std::string>& f
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::string ext = file.extension();
|
||||
std::vector<std::string> mods = GetApplication().getImportModules(ext.c_str());
|
||||
std::vector<std::string> mods = GetApplication().getImportModules(file.extension());
|
||||
if (!mods.empty()) {
|
||||
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(file.filePath().c_str());
|
||||
escapedstr = Base::Tools::escapeEncodeFilename(escapedstr);
|
||||
@@ -2905,9 +2887,8 @@ void Application::processCmdLineFiles()
|
||||
output = Base::Tools::escapeEncodeFilename(output);
|
||||
|
||||
const Base::FileInfo fi(output);
|
||||
const std::string ext = fi.extension();
|
||||
try {
|
||||
const std::vector<std::string> mods = GetApplication().getExportModules(ext.c_str());
|
||||
const std::vector<std::string> mods = GetApplication().getExportModules(fi.extension());
|
||||
if (!mods.empty()) {
|
||||
Base::Interpreter().loadModule(mods.front().c_str());
|
||||
Base::Interpreter().runStringArg("import %s",mods.front().c_str());
|
||||
|
||||
@@ -561,7 +561,7 @@ public:
|
||||
*
|
||||
* @param[in] extension The file type extension.
|
||||
*/
|
||||
std::vector<std::string> getImportModules(const char* extension) const;
|
||||
std::vector<std::string> getImportModules(const std::string& extension) const;
|
||||
|
||||
/// Get a list of all import modules.
|
||||
std::vector<std::string> getImportModules() const;
|
||||
@@ -572,7 +572,7 @@ public:
|
||||
* @param[in] Module The module name.
|
||||
* @return A list of file types (extensions) supported by the module.
|
||||
*/
|
||||
std::vector<std::string> getImportTypes(const char* Module) const;
|
||||
std::vector<std::string> getImportTypes(const std::string& Module) const;
|
||||
|
||||
/// Get a list of all import filetypes represented as extensions.
|
||||
std::vector<std::string> getImportTypes() const;
|
||||
@@ -583,7 +583,7 @@ public:
|
||||
* @param[in] extension The file type represented by its extension.
|
||||
* @return A map of filter description to module name.
|
||||
*/
|
||||
std::map<std::string, std::string> getImportFilters(const char* extension) const;
|
||||
std::map<std::string, std::string> getImportFilters(const std::string& extension) const;
|
||||
|
||||
/// Get a mapping of all import filters to their modules.
|
||||
std::map<std::string, std::string> getImportFilters() const;
|
||||
@@ -605,7 +605,7 @@ public:
|
||||
*
|
||||
* @copydetails getImportModules
|
||||
*/
|
||||
std::vector<std::string> getExportModules(const char* extension) const;
|
||||
std::vector<std::string> getExportModules(const std::string& extension) const;
|
||||
|
||||
/// Get a list of all export modules.
|
||||
std::vector<std::string> getExportModules() const;
|
||||
@@ -613,9 +613,9 @@ public:
|
||||
/**
|
||||
* @brief Get a list of filetypes that are supported by a module for export.
|
||||
*
|
||||
* @copydetails App::Application::getImportTypes(const char*) const
|
||||
* @copydetails App::Application::getImportTypes(const std::string&) const
|
||||
*/
|
||||
std::vector<std::string> getExportTypes(const char* Module) const;
|
||||
std::vector<std::string> getExportTypes(const std::string& Module) const;
|
||||
|
||||
/// Get a list of all export filetypes.
|
||||
std::vector<std::string> getExportTypes() const;
|
||||
@@ -623,9 +623,9 @@ public:
|
||||
/**
|
||||
* @brief Get the export filters with modules of a given filetype.
|
||||
*
|
||||
* @copydetails App::Application::getImportFilters(const char*) const
|
||||
* @copydetails App::Application::getImportFilters(const std::string&) const
|
||||
*/
|
||||
std::map<std::string, std::string> getExportFilters(const char* extension) const;
|
||||
std::map<std::string, std::string> getExportFilters(const std::string& extension) const;
|
||||
|
||||
/// Get a mapping of all export filters to their modules.
|
||||
std::map<std::string, std::string> getExportFilters() const;
|
||||
|
||||
@@ -760,7 +760,7 @@ PyObject* Application::sGetExportType(PyObject* /*self*/, PyObject* args)
|
||||
Py::Dict dict;
|
||||
std::vector<std::string> types = GetApplication().getExportTypes();
|
||||
for (const auto& it : types) {
|
||||
std::vector<std::string> modules = GetApplication().getExportModules(it.c_str());
|
||||
std::vector<std::string> modules = GetApplication().getExportModules(it);
|
||||
if (modules.empty()) {
|
||||
dict.setItem(it.c_str(), Py::None());
|
||||
}
|
||||
|
||||
@@ -1098,12 +1098,12 @@ SelectModule::Dict SelectModule::exportHandler(const QStringList& fileNames, con
|
||||
QFileInfo fi(fileName);
|
||||
QString ext = fi.completeSuffix().toLower();
|
||||
std::map<std::string, std::string> filters = App::GetApplication().getExportFilters(
|
||||
ext.toLatin1()
|
||||
ext.toStdString()
|
||||
);
|
||||
|
||||
if (filters.empty()) {
|
||||
ext = fi.suffix().toLower();
|
||||
filters = App::GetApplication().getExportFilters(ext.toLatin1());
|
||||
filters = App::GetApplication().getExportFilters(ext.toStdString());
|
||||
}
|
||||
|
||||
fileExtension[ext].push_back(fileName);
|
||||
@@ -1168,12 +1168,12 @@ SelectModule::Dict SelectModule::importHandler(const QStringList& fileNames, con
|
||||
QFileInfo fi(fileName);
|
||||
QString ext = fi.completeSuffix().toLower();
|
||||
std::map<std::string, std::string> filters = App::GetApplication().getImportFilters(
|
||||
ext.toLatin1()
|
||||
ext.toStdString()
|
||||
);
|
||||
|
||||
if (filters.empty()) {
|
||||
ext = fi.suffix().toLower();
|
||||
filters = App::GetApplication().getImportFilters(ext.toLatin1());
|
||||
filters = App::GetApplication().getImportFilters(ext.toStdString());
|
||||
}
|
||||
|
||||
fileExtension[ext].push_back(fileName);
|
||||
|
||||
@@ -2453,10 +2453,10 @@ void MainWindow::loadUrls(App::Document* doc, const QList<QUrl>& urls)
|
||||
info.setFile(info.symLinkTarget());
|
||||
}
|
||||
std::vector<std::string> module = App::GetApplication().getImportModules(
|
||||
info.completeSuffix().toLatin1()
|
||||
info.completeSuffix().toStdString()
|
||||
);
|
||||
if (module.empty()) {
|
||||
module = App::GetApplication().getImportModules(info.suffix().toLatin1());
|
||||
module = App::GetApplication().getImportModules(info.suffix().toStdString());
|
||||
}
|
||||
if (!module.empty()) {
|
||||
// ok, we support files with this extension
|
||||
|
||||
Reference in New Issue
Block a user