This repository was archived by the owner on Jun 15, 2023. It is now read-only.
File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 14
14
15
15
#include " disk_interface.h"
16
16
17
+ #include < algorithm>
18
+
17
19
#include < errno.h>
18
20
#include < stdio.h>
19
21
#include < string.h>
@@ -31,15 +33,16 @@ namespace {
31
33
32
34
string DirName (const string& path) {
33
35
#ifdef _WIN32
34
- const char kPathSeparator = ' \\ ' ;
36
+ const char kPathSeparators [] = " \\ / " ;
35
37
#else
36
- const char kPathSeparator = ' / ' ;
38
+ const char kPathSeparators [] = " / " ;
37
39
#endif
38
-
39
- string::size_type slash_pos = path.rfind (kPathSeparator );
40
+ string::size_type slash_pos = path.find_last_of (kPathSeparators );
40
41
if (slash_pos == string::npos)
41
42
return string (); // Nothing to do.
42
- while (slash_pos > 0 && path[slash_pos - 1 ] == kPathSeparator )
43
+ const char * const kEnd = kPathSeparators + strlen (kPathSeparators );
44
+ while (slash_pos > 0 &&
45
+ std::find (kPathSeparators , kEnd , path[slash_pos - 1 ]) != kEnd )
43
46
--slash_pos;
44
47
return path.substr (0 , slash_pos);
45
48
}
Original file line number Diff line number Diff line change @@ -93,7 +93,18 @@ TEST_F(DiskInterfaceTest, ReadFile) {
93
93
}
94
94
95
95
TEST_F (DiskInterfaceTest, MakeDirs) {
96
- EXPECT_TRUE (disk_.MakeDirs (" path/with/double//slash/" ));
96
+ string path = " path/with/double//slash/" ;
97
+ EXPECT_TRUE (disk_.MakeDirs (path.c_str ()));
98
+ FILE* f = fopen ((path + " a_file" ).c_str (), " w" );
99
+ EXPECT_TRUE (f);
100
+ EXPECT_EQ (0 , fclose (f));
101
+ #ifdef _WIN32
102
+ string path2 = " another\\ with\\ back\\\\ slashes\\ " ;
103
+ EXPECT_TRUE (disk_.MakeDirs (path2.c_str ()));
104
+ FILE* f2 = fopen ((path2 + " a_file" ).c_str (), " w" );
105
+ EXPECT_TRUE (f2);
106
+ EXPECT_EQ (0 , fclose (f2));
107
+ #endif
97
108
}
98
109
99
110
TEST_F (DiskInterfaceTest, RemoveFile) {
You can’t perform that action at this time.
0 commit comments