Fix handling short filenames (less than 4 characters)

- fixes https://github.com/google/draco/issues/108
This commit is contained in:
Pavel P 2017-08-06 22:33:38 -07:00
parent e2de4f8f43
commit 64c045bdae
3 changed files with 6 additions and 4 deletions

View File

@ -31,7 +31,8 @@ std::unique_ptr<Mesh> ReadMeshFromFile(const std::string &file_name,
std::unique_ptr<Mesh> mesh(new Mesh());
// Analyze file extension.
const std::string extension =
parser::ToLower(file_name.substr(file_name.size() - 4));
parser::ToLower(file_name.size() >= 4 ?
file_name.substr(file_name.size() - 4) : file_name);
if (extension == ".obj") {
// Wavefront OBJ file format.
ObjDecoder obj_decoder;

View File

@ -25,7 +25,8 @@ std::unique_ptr<PointCloud> ReadPointCloudFromFile(
const std::string &file_name) {
std::unique_ptr<PointCloud> pc(new PointCloud());
// Analyze file extension.
const std::string extension = file_name.substr(file_name.size() - 4);
const std::string extension = file_name.size() >= 4 ?
file_name.substr(file_name.size() - 4) : file_name;
if (extension == ".obj") {
// Wavefront OBJ file format.
ObjDecoder obj_decoder;

View File

@ -134,8 +134,8 @@ int main(int argc, char **argv) {
// Save the decoded geometry into a file.
// TODO(ostava): Currently only .ply and .obj are supported.
const std::string extension =
options.output.substr(options.output.size() - 4);
const std::string extension = options.output.size() >= 4 ?
options.output.substr(options.output.size() - 4) : options.output;
if (extension == ".obj") {
draco::ObjEncoder obj_encoder;
if (mesh) {