forked from coolwanglu/pdf2htmlEX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.cc
More file actions
73 lines (60 loc) · 1.41 KB
/
Copy pathpath.cc
File metadata and controls
73 lines (60 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Functions manipulating filenames and paths
*
* by WangLu
* 2012.11.29
*/
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "path.h"
using std::string;
namespace pdf2htmlEX {
void create_directories(const string & path)
{
if(path.empty()) return;
size_t idx = path.rfind('/');
if(idx != string::npos)
{
create_directories(path.substr(0, idx));
}
int r = mkdir(path.c_str(), S_IRWXU);
if(r != 0)
{
if(errno == EEXIST)
{
struct stat stat_buf;
if((stat(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
return;
}
throw string("Cannot create directory: ") + path;
}
}
bool is_truetype_suffix(const string & suffix)
{
return (suffix == ".ttf") || (suffix == ".ttc") || (suffix == ".otf");
}
string get_filename (const string & path)
{
size_t idx = path.rfind('/');
if(idx == string::npos)
return path;
else if (idx == path.size() - 1)
return "";
return path.substr(idx + 1);
}
string get_suffix(const string & path)
{
string fn = get_filename(path);
size_t idx = fn.rfind('.');
if(idx == string::npos)
return "";
else
{
string s = fn.substr(idx);
for(auto iter = s.begin(); iter != s.end(); ++iter)
*iter = tolower(*iter);
return s;
}
}
} //namespace pdf2htmlEX