Browse Source

Added detection of XML-derived file types by peeking the file contents

merge-requests/413/head
doe300 3 years ago
parent
commit
c021fad812
  1. 9
      src/source.cpp

9
src/source.cpp

@ -14,6 +14,7 @@
#include <boost/spirit/home/qi/char.hpp> #include <boost/spirit/home/qi/char.hpp>
#include <boost/spirit/home/qi/operator.hpp> #include <boost/spirit/home/qi/operator.hpp>
#include <boost/spirit/home/qi/string.hpp> #include <boost/spirit/home/qi/string.hpp>
#include <fstream>
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include <map> #include <map>
@ -88,6 +89,14 @@ Glib::RefPtr<Gsv::Language> Source::guess_language(const boost::filesystem::path
} }
} }
} }
else {
std::ifstream input(file_path.string(), std::ios::binary);
std::string tag(5, '\0');
if(input && input.read(&tag[0], static_cast<std::streamsize>(tag.size()))) {
if(tag == "<?xml")
language = language_manager->get_language("xml");
}
}
} }
else if(language->get_id() == "cuda") { else if(language->get_id() == "cuda") {
if(file_path.extension() == ".cuh") if(file_path.extension() == ".cuh")

Loading…
Cancel
Save