CortidQCT  1.2.2.52
CheckExtension.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <algorithm>
16 #include <string>
17 
18 namespace CortidQCT {
19 
21 namespace IO {
22 
23 inline std::string extension(std::string const &filename,
24  bool toLower = false) {
25 
26  std::string extension = "";
27  if (auto const dotPos = filename.find_last_of('.');
28  dotPos != std::string::npos) {
29  extension = filename.substr(dotPos + 1);
30  }
31 
32  if (toLower) {
33  std::transform(begin(extension), end(extension), begin(extension), tolower);
34  }
35  return extension;
36 }
37 
38 template <class Extensions>
39 bool checkExtensions(std::string const &filename, Extensions &&extensions) {
40  using std::begin;
41  using std::end;
42  using std::find;
43 
44  auto const ext = extension(filename, true);
45 
46  return find_if(begin(extensions), end(extensions), [&ext](auto const &rhs) {
47  std::string query = rhs;
48  std::transform(begin(query), end(query), begin(query), tolower);
49  return query == ext;
50  }) != end(extensions);
51 }
52 
53 } // namespace IO
54 
55 } // namespace CortidQCT
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23