Commit b54fb9cc authored by Erik Jensen's avatar Erik Jensen Committed by Commit Bot

Add AddExtensionASCII to FilePath

This complements the existing *ASCII methods, and makes it easier to
append a constant extension to a FilePath. Chrome Remote Desktop will use
this for in-progress file transfers.

Change-Id: Iac84f4809eb9bbbc399f3b5d3322978a7b7174b9
Reviewed-on: https://chromium-review.googlesource.com/c/1330342
Commit-Queue: Erik Jensen <rkjnsn@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611430}
parent 948b1233
...@@ -445,6 +445,15 @@ FilePath FilePath::AddExtension(StringPieceType extension) const { ...@@ -445,6 +445,15 @@ FilePath FilePath::AddExtension(StringPieceType extension) const {
return FilePath(str); return FilePath(str);
} }
FilePath FilePath::AddExtensionASCII(StringPiece extension) const {
DCHECK(IsStringASCII(extension));
#if defined(OS_WIN)
return AddExtension(ASCIIToUTF16(extension));
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
return AddExtension(extension);
#endif
}
FilePath FilePath::ReplaceExtension(StringPieceType extension) const { FilePath FilePath::ReplaceExtension(StringPieceType extension) const {
if (IsEmptyOrSpecialCase(BaseName().value())) if (IsEmptyOrSpecialCase(BaseName().value()))
return FilePath(); return FilePath();
......
...@@ -301,6 +301,10 @@ class BASE_EXPORT FilePath { ...@@ -301,6 +301,10 @@ class BASE_EXPORT FilePath {
// |extension| is empty. Returns "" if BaseName() == "." or "..". // |extension| is empty. Returns "" if BaseName() == "." or "..".
FilePath AddExtension(StringPieceType extension) const WARN_UNUSED_RESULT; FilePath AddExtension(StringPieceType extension) const WARN_UNUSED_RESULT;
// Like above, but takes the extension as an ASCII string. See AppendASCII for
// details on how this is handled.
FilePath AddExtensionASCII(StringPiece extension) const WARN_UNUSED_RESULT;
// Replaces the extension of |file_name| with |extension|. If |file_name| // Replaces the extension of |file_name| with |extension|. If |file_name|
// does not have an extension, then |extension| is added. If |extension| is // does not have an extension, then |extension| is added. If |extension| is
// empty, then the extension is removed from |file_name|. // empty, then the extension is removed from |file_name|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment