-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpath_string_tools.cpp
More file actions
50 lines (36 loc) · 1.22 KB
/
path_string_tools.cpp
File metadata and controls
50 lines (36 loc) · 1.22 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
#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 changeSeparatorInPath( _originStr, '\\', '/' );
}
//------------------------------------------------------------------------------
std::string toWindowsPath( const std::string & _originStr )
{
return changeSeparatorInPath( _originStr, '/', '\\' );
}
//------------------------------------------------------------------------------
std::string changeSeparatorInPath(
const std::string & _originStr, char _oldSeparator, char _newSeparator )
{
std::string result{ _originStr };
std::replace_if(
result.begin(), result.end(),
[&]( char _c ) { return _c == _oldSeparator; }, _newSeparator );
return result;
}
//------------------------------------------------------------------------------
}