1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/strings/utf_string_conversions.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +// Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ 1.9 +#define BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ 1.10 + 1.11 +#include <string> 1.12 + 1.13 +#include "base/base_export.h" 1.14 +#include "base/strings/string16.h" 1.15 +#include "base/strings/string_piece.h" 1.16 + 1.17 +namespace base { 1.18 + 1.19 +// These convert between UTF-8, -16, and -32 strings. They are potentially slow, 1.20 +// so avoid unnecessary conversions. The low-level versions return a boolean 1.21 +// indicating whether the conversion was 100% valid. In this case, it will still 1.22 +// do the best it can and put the result in the output buffer. The versions that 1.23 +// return strings ignore this error and just return the best conversion 1.24 +// possible. 1.25 +BASE_EXPORT bool WideToUTF8(const wchar_t* src, size_t src_len, 1.26 + std::string* output); 1.27 +BASE_EXPORT std::string WideToUTF8(const std::wstring& wide); 1.28 +BASE_EXPORT bool UTF8ToWide(const char* src, size_t src_len, 1.29 + std::wstring* output); 1.30 +BASE_EXPORT std::wstring UTF8ToWide(const StringPiece& utf8); 1.31 + 1.32 +BASE_EXPORT bool WideToUTF16(const wchar_t* src, size_t src_len, 1.33 + string16* output); 1.34 +BASE_EXPORT string16 WideToUTF16(const std::wstring& wide); 1.35 +BASE_EXPORT bool UTF16ToWide(const char16* src, size_t src_len, 1.36 + std::wstring* output); 1.37 +BASE_EXPORT std::wstring UTF16ToWide(const string16& utf16); 1.38 + 1.39 +BASE_EXPORT bool UTF8ToUTF16(const char* src, size_t src_len, string16* output); 1.40 +BASE_EXPORT string16 UTF8ToUTF16(const StringPiece& utf8); 1.41 +BASE_EXPORT bool UTF16ToUTF8(const char16* src, size_t src_len, 1.42 + std::string* output); 1.43 +BASE_EXPORT std::string UTF16ToUTF8(const string16& utf16); 1.44 + 1.45 +// We are trying to get rid of wstring as much as possible, but it's too big 1.46 +// a mess to do it all at once. These conversions should be used when we 1.47 +// really should just be passing a string16 around, but we haven't finished 1.48 +// porting whatever module uses wstring and the conversion is being used as a 1.49 +// stopcock. This makes it easy to grep for the ones that should be removed. 1.50 +#if defined(OS_WIN) 1.51 +# define WideToUTF16Hack 1.52 +# define UTF16ToWideHack 1.53 +#else 1.54 +# define WideToUTF16Hack WideToUTF16 1.55 +# define UTF16ToWideHack UTF16ToWide 1.56 +#endif 1.57 + 1.58 +// These convert an ASCII string, typically a hardcoded constant, to a 1.59 +// UTF16/Wide string. 1.60 +BASE_EXPORT std::wstring ASCIIToWide(const StringPiece& ascii); 1.61 +BASE_EXPORT string16 ASCIIToUTF16(const StringPiece& ascii); 1.62 + 1.63 +} // namespace base 1.64 + 1.65 +// TODO(brettw) remove these when callers are fixed up. 1.66 +using base::WideToUTF8; 1.67 +using base::UTF8ToWide; 1.68 +using base::WideToUTF16; 1.69 +using base::UTF16ToWide; 1.70 +using base::UTF8ToUTF16; 1.71 +using base::UTF16ToUTF8; 1.72 +using base::ASCIIToWide; 1.73 +using base::ASCIIToUTF16; 1.74 + 1.75 +#endif // BASE_STRINGS_UTF_STRING_CONVERSIONS_H_