OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 | 7 |
8 // These includes are just for the *Hack functions, and should be removed | 8 // These includes are just for the *Hack functions, and should be removed |
9 // when those functions are removed. | 9 // when those functions are removed. |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 StringType ext = Extension(); | 306 StringType ext = Extension(); |
307 StringType ret = RemoveExtension().value(); | 307 StringType ret = RemoveExtension().value(); |
308 ret.append(suffix); | 308 ret.append(suffix); |
309 ret.append(ext); | 309 ret.append(ext); |
310 return FilePath(ret); | 310 return FilePath(ret); |
311 } | 311 } |
312 | 312 |
| 313 FilePath FilePath::InsertBeforeExtensionASCII(const StringPiece& suffix) const { |
| 314 DCHECK(IsStringASCII(suffix)); |
| 315 #if defined(OS_WIN) |
| 316 return InsertBeforeExtension(ASCIIToWide(suffix)); |
| 317 #elif defined(OS_POSIX) |
| 318 return InsertBeforeExtension(suffix.as_string()); |
| 319 #endif |
| 320 } |
| 321 |
313 FilePath FilePath::ReplaceExtension(const StringType& extension) const { | 322 FilePath FilePath::ReplaceExtension(const StringType& extension) const { |
314 if (path_.empty()) | 323 if (path_.empty()) |
315 return FilePath(); | 324 return FilePath(); |
316 | 325 |
317 StringType base = BaseName().value(); | 326 StringType base = BaseName().value(); |
318 if (base.empty()) | 327 if (base.empty()) |
319 return FilePath(); | 328 return FilePath(); |
320 if (*(base.end() - 1) == kExtensionSeparator) { | 329 if (*(base.end() - 1) == kExtensionSeparator) { |
321 // Special case "." and ".." | 330 // Special case "." and ".." |
322 if (base == kCurrentDirectory || base == kParentDirectory) { | 331 if (base == kCurrentDirectory || base == kParentDirectory) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 --pos) { | 454 --pos) { |
446 // If the string only has two separators and they're at the beginning, | 455 // If the string only has two separators and they're at the beginning, |
447 // don't strip them, unless the string began with more than two separators. | 456 // don't strip them, unless the string began with more than two separators. |
448 if (pos != start + 1 || last_stripped == start + 2 || | 457 if (pos != start + 1 || last_stripped == start + 2 || |
449 !IsSeparator(path_[start - 1])) { | 458 !IsSeparator(path_[start - 1])) { |
450 path_.resize(pos - 1); | 459 path_.resize(pos - 1); |
451 last_stripped = pos; | 460 last_stripped = pos; |
452 } | 461 } |
453 } | 462 } |
454 } | 463 } |
OLD | NEW |