↰ Return to documentation for file (morpheus/_lib/src/objects/file_types.cpp
)
#include "morpheus/objects/file_types.hpp"
#include "morpheus/utilities/string_util.hpp"
#include <filesystem>
#include <sstream>// ostringstream needed by MORPHEUS_CONCAT_STR
#include <stdexcept>
namespace morpheus {
FileTypes FileTypesInterfaceProxy::determine_file_type(const std::string &filename)
{
return morpheus::determine_file_type(filename);
}
} // namespace morpheus
morpheus::FileTypes morpheus::determine_file_type(const std::string &filename)
{
auto filename_path = std::filesystem::path(filename);
if (filename_path.extension() == ".json" || filename_path.extension() == ".jsonlines")
{
return FileTypes::JSON;
}
else if (filename_path.extension() == ".csv")
{
return FileTypes::CSV;
}
else
{
throw std::runtime_error(MORPHEUS_CONCAT_STR("Unsupported extension '"
<< filename_path.extension()
<< "' with 'auto' type. 'auto' only works with: csv, json"));
}
}