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

Function CleanPath

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

Source from the content-addressed store, hash-verified

145}
146
147string CleanPath(StringPiece unclean_path) {
148 string path(unclean_path);
149 const char* src = path.c_str();
150 string::iterator dst = path.begin();
151
152 // Check for absolute path and determine initial backtrack limit.
153 const bool is_absolute_path = *src == '/';
154 if (is_absolute_path) {
155 *dst++ = *src++;
156 while (*src == '/') ++src;
157 }
158 string::const_iterator backtrack_limit = dst;
159
160 // Process all parts
161 while (*src) {
162 bool parsed = false;
163
164 if (src[0] == '.') {
165 // 1dot ".<whateverisnext>", check for END or SEP.
166 if (src[1] == '/' || !src[1]) {
167 if (*++src) {
168 ++src;
169 }
170 parsed = true;
171 } else if (src[1] == '.' && (src[2] == '/' || !src[2])) {
172 // 2dot END or SEP (".." | "../<whateverisnext>").
173 src += 2;
174 if (dst != backtrack_limit) {
175 // We can backtrack the previous part
176 for (--dst; dst != backtrack_limit && dst[-1] != '/'; --dst) {
177 // Empty.
178 }
179 } else if (!is_absolute_path) {
180 // Failed to backtrack and we can't skip it either. Rewind and copy.
181 src -= 2;
182 *dst++ = *src++;
183 *dst++ = *src++;
184 if (*src) {
185 *dst++ = *src;
186 }
187 // We can never backtrack over a copied "../" part so set new limit.
188 backtrack_limit = dst;
189 }
190 if (*src) {
191 ++src;
192 }
193 parsed = true;
194 }
195 }
196
197 // If not parsed, copy entire part until the next SEP or EOS.
198 if (!parsed) {
199 while (*src && *src != '/') {
200 *dst++ = *src++;
201 }
202 if (*src) {
203 *dst++ = *src++;
204 }

Callers 2

TESTFunction · 0.85
TranslateNameMethod · 0.85

Calls 4

c_strMethod · 0.80
beginMethod · 0.45
resizeMethod · 0.45
assignMethod · 0.45

Tested by 1

TESTFunction · 0.68