-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpath_string_tools.cpp
More file actions
58 lines (41 loc) · 1.29 KB
/
path_string_tools.cpp
File metadata and controls
58 lines (41 loc) · 1.29 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
#include "tools/path_string_tools.hpp"
#include <algorithm>
//------------------------------------------------------------------------------
namespace tools {
//------------------------------------------------------------------------------
std::string toPath( const std::string & _originStr )
{
#ifdef _WIN32
return toWindowsPath( _originStr );
#else
return toUnixPath( _originStr );
#endif
}
//------------------------------------------------------------------------------
std::string toUnixPath( const std::string & _originStr )
{
return changeSeperatorInPath( _originStr, '\\', '/' );
}
//------------------------------------------------------------------------------
std::string toWindowsPath( const std::string & _originStr )
{
return changeSeperatorInPath( _originStr, '/', '\\' );
}
//------------------------------------------------------------------------------
std::string changeSeperatorInPath(
const std::string & _originStr,
char _oldSeperator,
char _newSeperator
)
{
std::string result{ _originStr };
std::replace_if(
result.begin(),
result.end(),
[&]( char _c ){ return _c == _oldSeperator; },
_newSeperator
);
return result;
}
//------------------------------------------------------------------------------
}