blob: f1ddf046b4138d0a942d97e9dacf700d4b849662 (
plain)
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
|
#include "file_name_utils.hpp"
namespace my
{
void GetNameWithoutExt(string & name)
{
string::size_type const i = name.find_last_of(".");
if (i != string::npos)
name.erase(i);
}
string GetFileExtension(string const & name)
{
size_t const pos = name.find_last_of("./\\");
return ((pos != string::npos && name[pos] == '.') ? name.substr(pos) : string());
}
void GetNameFromFullPath(string & name)
{
string::size_type const i = name.find_last_of("/\\");
if (i != string::npos)
name = name.substr(i+1);
}
string GetNativeSeparator()
{
#ifdef OMIM_OS_WINDOWS
return "\\";
#else
return "/";
#endif
}
string JoinFoldersToPath(const string & folder, const string & file)
{
return folder + GetNativeSeparator() + file;
}
string JoinFoldersToPath(const string & folder1, const string & folder2, const string & file)
{
string nativeSeparator = GetNativeSeparator();
return folder1 + nativeSeparator + folder2 + nativeSeparator + file;
}
string JoinFoldersToPath(const string & folder1, const string & folder2, const string & folder3, const string & file)
{
string nativeSeparator = GetNativeSeparator();
return folder1 + nativeSeparator + folder2 + nativeSeparator + folder3 + nativeSeparator + file;
}
string JoinFoldersToPath(const vector<string> & folders, const string & file)
{
if (folders.empty())
return file;
string nativeSeparator = GetNativeSeparator();
string result;
for (size_t i = 0; i < folders.size(); ++i)
result = result + folders[i] + nativeSeparator;
result += file;
return result;
}
}
|