MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / SplitPath

Function SplitPath

tensorflow/core/lib/io/path.cc:71–93  ·  view source on GitHub ↗

Return the parts of the URI, split on the final "/" in the path. If there is no "/" in the path, the first part of the output is the scheme and host, and the second is the path. If the only "/" in the path is the first character, it is included in the first part of the output.

Source from the content-addressed store, hash-verified

69// the second is the path. If the only "/" in the path is the first character,
70// it is included in the first part of the output.
71std::pair<StringPiece, StringPiece> SplitPath(StringPiece uri) {
72 StringPiece scheme, host, path;
73 ParseURI(uri, &scheme, &host, &path);
74
75 auto pos = path.rfind('/');
76#ifdef PLATFORM_WINDOWS
77 if (pos == StringPiece::npos) pos = path.rfind('\\');
78#endif
79 // Handle the case with no '/' in 'path'.
80 if (pos == StringPiece::npos)
81 return std::make_pair(StringPiece(uri.begin(), host.end() - uri.begin()),
82 path);
83
84 // Handle the case with a single leading '/' in 'path'.
85 if (pos == 0)
86 return std::make_pair(
87 StringPiece(uri.begin(), path.begin() + 1 - uri.begin()),
88 StringPiece(path.data() + 1, path.size() - 1));
89
90 return std::make_pair(
91 StringPiece(uri.begin(), path.begin() + pos - uri.begin()),
92 StringPiece(path.data() + pos + 1, path.size() - (pos + 1)));
93}
94
95// Return the parts of the basename of path, split on the final ".".
96// If there is no "." in the basename or "." is the final character in the

Callers 2

DirnameFunction · 0.85
BasenameFunction · 0.85

Calls 5

ParseURIFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected