OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "public/platform/FilePathConversion.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "public/platform/WebString.h" |
| 9 #include "wtf/text/StringUTF8Adaptor.h" |
| 10 #include "wtf/text/WTFString.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 base::FilePath WebStringToFilePath(const WebString& webString) |
| 15 { |
| 16 if (webString.isEmpty()) |
| 17 return base::FilePath(); |
| 18 |
| 19 String str = webString; |
| 20 if (!str.is8Bit()) { |
| 21 return base::FilePath::FromUTF16Unsafe( |
| 22 base::StringPiece16(str.characters16(), str.length())); |
| 23 } |
| 24 |
| 25 #if OS(POSIX) |
| 26 StringUTF8Adaptor utf8(str); |
| 27 return base::FilePath::FromUTF8Unsafe(utf8.asStringPiece()); |
| 28 #else |
| 29 const LChar* data8 = str.characters8(); |
| 30 return base::FilePath::FromUTF16Unsafe( |
| 31 base::string16(data8, data8 + str.length())); |
| 32 #endif |
| 33 } |
| 34 |
| 35 } // namespace blink |
OLD | NEW |