Browse Source

Any*{Importer,Converter}: use string view APIs for extension matching.

Now that Path is std::string-free, this is all very possible, very
convenient and very pretty.
pull/556/head
Vladimír Vondruš 4 years ago
parent
commit
3fc9028b54
  1. 31
      src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp
  2. 145
      src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp
  3. 121
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp
  4. 10
      src/MagnumPlugins/AnySceneConverter/AnySceneConverter.cpp
  5. 5
      src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp

31
src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp

@ -30,12 +30,15 @@
#include <Corrade/PluginManager/PluginMetadata.h>
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h>
#include "MagnumPlugins/Implementation/propagateConfiguration.h"
namespace Magnum { namespace Audio {
using namespace Containers::Literals;
AnyImporter::AnyImporter(PluginManager::Manager<AbstractImporter>& manager): AbstractImporter{manager} {}
AnyImporter::AnyImporter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImporter{manager, plugin} {}
@ -51,21 +54,23 @@ void AnyImporter::doClose() { _in = nullptr; }
void AnyImporter::doOpenFile(const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo lowercase only the extension, once Directory::split() is done */
const std::string normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
std::string plugin;
if(Utility::String::endsWith(normalized, ".aac"))
plugin = "AacAudioImporter";
else if(Utility::String::endsWith(normalized, ".mp3"))
plugin = "Mp3AudioImporter";
else if(Utility::String::endsWith(normalized, ".ogg"))
plugin = "VorbisAudioImporter";
else if(Utility::String::endsWith(normalized, ".wav"))
plugin = "WavAudioImporter";
else if(Utility::String::endsWith(normalized, ".flac"))
plugin = "FlacAudioImporter";
Containers::StringView plugin;
if(normalizedExtension == ".aac"_s)
plugin = "AacAudioImporter"_s;
else if(normalizedExtension == ".mp3"_s)
plugin = "Mp3AudioImporter"_s;
else if(normalizedExtension == ".ogg"_s)
plugin = "VorbisAudioImporter"_s;
else if(normalizedExtension == ".wav"_s)
plugin = "WavAudioImporter"_s;
else if(normalizedExtension == ".flac"_s)
plugin = "FlacAudioImporter"_s;
else {
Error{} << "Audio::AnyImporter::openFile(): cannot determine the format of" << filename;
return;

145
src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp

@ -31,6 +31,7 @@
#include <Corrade/PluginManager/PluginMetadata.h>
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h>
#include "Magnum/Trade/ImageData.h"
@ -65,13 +66,14 @@ ImageConverterFeatures AnyImageConverter::doFeatures() const {
bool AnyImageConverter::doConvertToFile(const ImageView1D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 1D image";
@ -108,32 +110,33 @@ bool AnyImageConverter::doConvertToFile(const ImageView1D& image, const Containe
bool AnyImageConverter::doConvertToFile(const ImageView2D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".bmp"_s))
if(normalizedExtension == ".bmp"_s)
plugin = "BmpImageConverter"_s;
else if(normalized.hasSuffix(".basis"_s))
else if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s))
else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".hdr"_s))
else if(normalizedExtension == ".hdr"_s)
plugin = "HdrImageConverter"_s;
else if(normalized.hasSuffix(".jpg"_s) ||
normalized.hasSuffix(".jpeg"_s) ||
normalized.hasSuffix(".jpe"_s))
else if(normalizedExtension == ".jpg"_s ||
normalizedExtension == ".jpeg"_s ||
normalizedExtension == ".jpe"_s)
plugin = "JpegImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s))
else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else if(normalized.hasSuffix(".png"_s))
else if(normalizedExtension == ".png"_s)
plugin = "PngImageConverter"_s;
else if(normalized.hasSuffix(".tga"_s) ||
normalized.hasSuffix(".vda"_s) ||
normalized.hasSuffix(".icb"_s) ||
normalized.hasSuffix( ".vst"_s))
else if(normalizedExtension == ".tga"_s ||
normalizedExtension == ".vda"_s ||
normalizedExtension == ".icb"_s ||
normalizedExtension == ".vst"_s)
plugin = "TgaImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 2D image";
@ -170,17 +173,18 @@ bool AnyImageConverter::doConvertToFile(const ImageView2D& image, const Containe
bool AnyImageConverter::doConvertToFile(const ImageView3D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".basis"_s))
if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s))
else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s))
else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 3D image";
@ -217,13 +221,14 @@ bool AnyImageConverter::doConvertToFile(const ImageView3D& image, const Containe
bool AnyImageConverter::doConvertToFile(const CompressedImageView1D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 1D image";
@ -260,13 +265,14 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView1D& image, cons
bool AnyImageConverter::doConvertToFile(const CompressedImageView2D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 2D image";
@ -303,13 +309,14 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView2D& image, cons
bool AnyImageConverter::doConvertToFile(const CompressedImageView3D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 3D image";
@ -346,13 +353,14 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView3D& image, cons
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView1D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 1D image";
@ -389,17 +397,18 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageV
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView2D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".basis"_s))
if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s))
else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s))
else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 2D image";
@ -436,17 +445,18 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageV
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView3D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".basis"_s))
if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s))
else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s))
else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 3D image";
@ -483,13 +493,14 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageV
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView1D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 1D image";
@ -526,13 +537,14 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const Compre
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView2D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 2D image";
@ -569,13 +581,14 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const Compre
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView3D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 3D image";

121
src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp

@ -33,6 +33,7 @@
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h>
#include "Magnum/Trade/ImageData.h"
@ -40,6 +41,8 @@
namespace Magnum { namespace Trade {
using namespace Containers::Literals;
AnyImageImporter::AnyImageImporter(PluginManager::Manager<AbstractImporter>& manager): AbstractImporter{manager} {}
AnyImageImporter::AnyImageImporter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImporter{manager, plugin} {}
@ -61,65 +64,67 @@ void AnyImageImporter::doClose() {
void AnyImageImporter::doOpenFile(const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo lowercase only the extension, once Directory::split() is done */
const std::string normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
std::string plugin;
if(Utility::String::endsWith(normalized, ".basis"))
plugin = "BasisImporter";
else if(Utility::String::endsWith(normalized, ".bmp"))
plugin = "BmpImporter";
else if(Utility::String::endsWith(normalized, ".dds"))
plugin = "DdsImporter";
else if(Utility::String::endsWith(normalized, ".exr"))
plugin = "OpenExrImporter";
else if(Utility::String::endsWith(normalized, ".gif"))
plugin = "GifImporter";
else if(Utility::String::endsWith(normalized, ".hdr"))
plugin = "HdrImporter";
else if(Utility::String::endsWith(normalized, ".ico") ||
Utility::String::endsWith(normalized, ".cur"))
plugin = "IcoImporter";
else if(Utility::String::endsWith(normalized, ".jpg") ||
Utility::String::endsWith(normalized, ".jpeg") ||
Utility::String::endsWith(normalized, ".jpe"))
plugin = "JpegImporter";
else if(Utility::String::endsWith(normalized, ".jp2"))
plugin = "Jpeg2000Importer";
else if(Utility::String::endsWith(normalized, ".ktx2"))
plugin = "KtxImporter";
else if(Utility::String::endsWith(normalized, ".mng"))
plugin = "MngImporter";
else if(Utility::String::endsWith(normalized, ".pbm"))
plugin = "PbmImporter";
else if(Utility::String::endsWith(normalized, ".pcx"))
plugin = "PcxImporter";
else if(Utility::String::endsWith(normalized, ".pgm"))
plugin = "PgmImporter";
else if(Utility::String::endsWith(normalized, ".pic"))
plugin = "PicImporter";
else if(Utility::String::endsWith(normalized, ".pnm"))
plugin = "PnmImporter";
else if(Utility::String::endsWith(normalized, ".png"))
plugin = "PngImporter";
else if(Utility::String::endsWith(normalized, ".ppm"))
plugin = "PpmImporter";
else if(Utility::String::endsWith(normalized, ".psd"))
plugin = "PsdImporter";
else if(Utility::String::endsWith(normalized, ".sgi") ||
Utility::String::endsWith(normalized, ".bw") ||
Utility::String::endsWith(normalized, ".rgb") ||
Utility::String::endsWith(normalized, ".rgba"))
plugin = "SgiImporter";
else if(Utility::String::endsWith(normalized, ".tif") ||
Utility::String::endsWith(normalized, ".tiff"))
plugin = "TiffImporter";
else if(Utility::String::endsWith(normalized, ".tga") ||
Utility::String::endsWith(normalized, ".vda") ||
Utility::String::endsWith(normalized, ".icb") ||
Utility::String::endsWith(normalized, ".vst"))
plugin = "TgaImporter";
Containers::StringView plugin;
if(normalizedExtension == ".basis"_s)
plugin = "BasisImporter"_s;
else if(normalizedExtension == ".bmp"_s)
plugin = "BmpImporter"_s;
else if(normalizedExtension == ".dds"_s)
plugin = "DdsImporter"_s;
else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImporter"_s;
else if(normalizedExtension == ".gif"_s)
plugin = "GifImporter"_s;
else if(normalizedExtension == ".hdr"_s)
plugin = "HdrImporter"_s;
else if(normalizedExtension == ".ico"_s ||
normalizedExtension == ".cur"_s)
plugin = "IcoImporter"_s;
else if(normalizedExtension == ".jpg"_s ||
normalizedExtension == ".jpeg"_s ||
normalizedExtension == ".jpe"_s)
plugin = "JpegImporter"_s;
else if(normalizedExtension == ".jp2"_s)
plugin = "Jpeg2000Importer"_s;
else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImporter"_s;
else if(normalizedExtension == ".mng"_s)
plugin = "MngImporter"_s;
else if(normalizedExtension == ".pbm"_s)
plugin = "PbmImporter"_s;
else if(normalizedExtension == ".pcx"_s)
plugin = "PcxImporter"_s;
else if(normalizedExtension == ".pgm"_s)
plugin = "PgmImporter"_s;
else if(normalizedExtension == ".pic"_s)
plugin = "PicImporter"_s;
else if(normalizedExtension == ".pnm"_s)
plugin = "PnmImporter"_s;
else if(normalizedExtension == ".png"_s)
plugin = "PngImporter"_s;
else if(normalizedExtension == ".ppm"_s)
plugin = "PpmImporter"_s;
else if(normalizedExtension == ".psd"_s)
plugin = "PsdImporter"_s;
else if(normalizedExtension == ".sgi"_s ||
normalizedExtension == ".bw"_s ||
normalizedExtension == ".rgb"_s ||
normalizedExtension == ".rgba"_s)
plugin = "SgiImporter"_s;
else if(normalizedExtension == ".tif"_s ||
normalizedExtension == ".tiff"_s)
plugin = "TiffImporter"_s;
else if(normalizedExtension == ".tga"_s ||
normalizedExtension == ".vda"_s ||
normalizedExtension == ".icb"_s ||
normalizedExtension == ".vst"_s)
plugin = "TgaImporter"_s;
else {
Error{} << "Trade::AnyImageImporter::openFile(): cannot determine the format of" << filename;
return;
@ -161,7 +166,7 @@ void AnyImageImporter::doOpenData(Containers::Array<char>&& data, DataFlags) {
CORRADE_INTERNAL_ASSERT(manager());
/* So we can use the convenient hasSuffix() API */
/* So we can use the convenient hasPrefix() API */
const Containers::ArrayView<const char> dataView = data;
const Containers::StringView dataString = dataView;

10
src/MagnumPlugins/AnySceneConverter/AnySceneConverter.cpp

@ -31,6 +31,7 @@
#include <Corrade/PluginManager/PluginMetadata.h>
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h>
#include "Magnum/Trade/ImageData.h"
@ -53,13 +54,14 @@ SceneConverterFeatures AnySceneConverter::doFeatures() const {
bool AnySceneConverter::doConvertToFile(const MeshData& mesh, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::StringView normalized = Utility::String::lowercase(filename);
/* We don't detect any double extensions yet, so we can normalize just the
extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ply"_s))
if(normalizedExtension == ".ply"_s)
plugin = "StanfordSceneConverter"_s;
else {
Error{} << "Trade::AnySceneConverter::convertToFile(): cannot determine the format of" << filename;

5
src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp

@ -32,6 +32,7 @@
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */
#include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h>
#include "MagnumPlugins/Implementation/propagateConfiguration.h"
@ -122,8 +123,8 @@ Containers::StringView stringForFormat(const Format format) {
Format formatForExtension(const char* prefix, const Containers::StringView filename) {
/* Can't reliably lowercase just the extension as we detect double
extensions as well */
const Containers::String normalized = Utility::String::lowercase(filename);
extensions as well. But we can lowercase just the filename, at least. */
const Containers::String normalized = Utility::String::lowercase(Utility::Path::split(filename).second());
/* https://github.com/KhronosGroup/SPIRV-Tools/blob/a715b1b4053519ad0f2bdb2d22ace35d35867cff/README.md#command-line-tools
"It's a convention to name SPIR-V assembly and binary files with suffix

Loading…
Cancel
Save