Abstract out the path separator and make use of it in JoinPath.
This lays some ground work for correctly dealing with paths on Windows. PiperOrigin-RevId: 295859552 Change-Id: I72eb50f69c33df0916bd68e90196819f7b22ed2c
This commit is contained in:
parent
93264c2830
commit
0623e844cc
@ -36,6 +36,11 @@ limitations under the License.
|
|||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
namespace io {
|
namespace io {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const char kPathSep[] = "/";
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
string JoinPathImpl(std::initializer_list<StringPiece> paths) {
|
string JoinPathImpl(std::initializer_list<StringPiece> paths) {
|
||||||
string result;
|
string result;
|
||||||
@ -48,18 +53,12 @@ string JoinPathImpl(std::initializer_list<StringPiece> paths) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result[result.size() - 1] == '/') {
|
if (IsAbsolutePath(path)) path = path.substr(1);
|
||||||
if (IsAbsolutePath(path)) {
|
|
||||||
strings::StrAppend(&result, path.substr(1));
|
if (result[result.size() - 1] == kPathSep[0]) {
|
||||||
} else {
|
strings::StrAppend(&result, path);
|
||||||
strings::StrAppend(&result, path);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (IsAbsolutePath(path)) {
|
strings::StrAppend(&result, kPathSep, path);
|
||||||
strings::StrAppend(&result, path);
|
|
||||||
} else {
|
|
||||||
strings::StrAppend(&result, "/", path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +106,7 @@ std::pair<StringPiece, StringPiece> SplitBasename(StringPiece path) {
|
|||||||
StringPiece(path.data(), pos),
|
StringPiece(path.data(), pos),
|
||||||
StringPiece(path.data() + pos + 1, path.size() - (pos + 1)));
|
StringPiece(path.data() + pos + 1, path.size() - (pos + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
bool IsAbsolutePath(StringPiece path) {
|
bool IsAbsolutePath(StringPiece path) {
|
||||||
|
Loading…
Reference in New Issue
Block a user