FileName.cc
Go to the documentation of this file.
1 
22 #include <utl/FileName.h>
23 #include <boost/filesystem/path.hpp>
24 #include <sys/stat.h>
25 
26 namespace fs = boost::filesystem;
27 using std::string;
28 
29 
30 namespace utl {
31 
32  fs::path
33  BareFilePath(const fs::path& thePath)
34  {
35  const fs::path head = thePath.branch_path();
36 #if BOOST_FILESYSTEM_VERSION < 3
37  const string tail = thePath.leaf();
38 #else
39  const string tail = thePath.leaf().string();
40 #endif
41  return head / tail.substr(0, tail.rfind("."));
42  }
43 
44 
45  std::string
46  BareFileName(const fs::path& thePath)
47  {
48 #if BOOST_FILESYSTEM_VERSION < 3
49  const string tail = thePath.leaf();
50 #else
51  const string tail = thePath.leaf().string();
52 #endif
53  return tail.substr(0, tail.rfind("."));
54  }
55 
56 
57  std::string
58  FileExtension(const fs::path& thePath)
59  {
60 #if BOOST_FILESYSTEM_VERSION < 3
61  const string tail = thePath.leaf();
62 #else
63  const string tail = thePath.leaf().string();
64 #endif
65  const string::size_type pos = tail.rfind(".");
66  if (pos != string::npos)
67  return tail.substr(pos, tail.size());
68  return "";
69  }
70 
71 
72  fs::path
73  operator+(const fs::path& thePath, const string& extra)
74  {
75  const fs::path head = thePath.branch_path();
76 #if BOOST_FILESYSTEM_VERSION < 3
77  const string tail = thePath.leaf() + extra;
78 #else
79  const string tail = thePath.leaf().string() + extra;
80 #endif
81  return head / tail;
82  }
83 
84 
85  namespace File {
86 
87  bool
88  Exists(const string& filename)
89  {
90  struct stat buffer;
91  return !stat(filename.c_str(), &buffer);
92  }
93 
94  }
95 
96 }
fs::path operator+(const fs::path &thePath, const string &extra)
Definition: FileName.cc:73
bool Exists(const string &filename)
Definition: FileName.cc:88
std::string BareFileName(const fs::path &thePath)
Definition: FileName.cc:46
fs::path BareFilePath(const fs::path &thePath)
Definition: FileName.cc:33
std::string FileExtension(const fs::path &thePath)
Definition: FileName.cc:58
char * filename
Definition: dump1090.h:266

, generated on Tue Sep 26 2023.