Fix circular dependencies between optional, array_view, and rtc_base.
This splits things out of rtc_base and makes dependencies explicit. Bug: webrtc:6828 Change-Id: Ib813c7bd9e4de7ab015acb917bc09ee7204ba7bd Reviewed-on: https://webrtc-review.googlesource.com/31940 Commit-Queue: Patrik Höglund <phoglund@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21245}
This commit is contained in:

committed by
Commit Bot

parent
10a8e7a9b5
commit
a9e0924fa7
@ -19,6 +19,7 @@
|
||||
#if defined(WEBRTC_WIN)
|
||||
#include <malloc.h>
|
||||
#include <wchar.h>
|
||||
#include <windows.h>
|
||||
#define alloca _alloca
|
||||
#endif // WEBRTC_WIN
|
||||
|
||||
@ -295,6 +296,43 @@ struct Traits<wchar_t> {
|
||||
|
||||
#endif // WEBRTC_WIN
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// UTF helpers (Windows only)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
|
||||
inline std::wstring ToUtf16(const char* utf8, size_t len) {
|
||||
int len16 = ::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len),
|
||||
nullptr, 0);
|
||||
wchar_t* ws = STACK_ARRAY(wchar_t, len16);
|
||||
::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len), ws, len16);
|
||||
return std::wstring(ws, len16);
|
||||
}
|
||||
|
||||
inline std::wstring ToUtf16(const std::string& str) {
|
||||
return ToUtf16(str.data(), str.length());
|
||||
}
|
||||
|
||||
inline std::string ToUtf8(const wchar_t* wide, size_t len) {
|
||||
int len8 = ::WideCharToMultiByte(CP_UTF8, 0, wide, static_cast<int>(len),
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
char* ns = STACK_ARRAY(char, len8);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wide, static_cast<int>(len), ns, len8,
|
||||
nullptr, nullptr);
|
||||
return std::string(ns, len8);
|
||||
}
|
||||
|
||||
inline std::string ToUtf8(const wchar_t* wide) {
|
||||
return ToUtf8(wide, wcslen(wide));
|
||||
}
|
||||
|
||||
inline std::string ToUtf8(const std::wstring& wstr) {
|
||||
return ToUtf8(wstr.data(), wstr.length());
|
||||
}
|
||||
|
||||
#endif // WEBRTC_WIN
|
||||
|
||||
// Replaces all occurrences of "search" with "replace".
|
||||
void replace_substrs(const char *search,
|
||||
size_t search_len,
|
||||
|
Reference in New Issue
Block a user