[a11y] Delegate UTF8ToUTF16 to FML (flutter/engine#31376)
Delegates string encoding conversions between UTF-8 and UTF-16 strings in //third_party/accessibility/base to our existing implementations in FML. Issue: https://github.com/flutter/flutter/issues/98061
This commit is contained in:
@@ -2109,8 +2109,6 @@ FILE: ../../../flutter/third_party/accessibility/base/simple_token.h
|
||||
FILE: ../../../flutter/third_party/accessibility/base/string_utils.cc
|
||||
FILE: ../../../flutter/third_party/accessibility/base/string_utils.h
|
||||
FILE: ../../../flutter/third_party/accessibility/base/string_utils_unittest.cc
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/string_conversion.cc
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/string_conversion.h
|
||||
FILE: ../../../flutter/third_party/accessibility/gfx/transform.cc
|
||||
FILE: ../../../flutter/third_party/accessibility/gfx/transform.h
|
||||
FILE: ../../../flutter/third_party/tonic/common/build_config.h
|
||||
|
||||
@@ -35,8 +35,6 @@ source_set("base") {
|
||||
"win/scoped_safearray.h",
|
||||
"win/scoped_variant.cc",
|
||||
"win/scoped_variant.h",
|
||||
"win/string_conversion.cc",
|
||||
"win/string_conversion.h",
|
||||
"win/variant_util.h",
|
||||
"win/variant_vector.cc",
|
||||
"win/variant_vector.h",
|
||||
@@ -52,6 +50,7 @@ source_set("base") {
|
||||
|
||||
public_deps = [
|
||||
"numerics",
|
||||
"//flutter/fml:string_conversion",
|
||||
"//flutter/third_party/accessibility/ax_build",
|
||||
"//third_party/dart/runtime/third_party/double-conversion/src:libdouble_conversion",
|
||||
]
|
||||
|
||||
@@ -11,12 +11,9 @@
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
#include "flutter/fml/string_conversion.h"
|
||||
#include "third_party/dart/runtime/third_party/double-conversion/src/double-conversion.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "base/win/string_conversion.h"
|
||||
#endif
|
||||
|
||||
#include "no_destructor.h"
|
||||
|
||||
namespace base {
|
||||
@@ -68,21 +65,11 @@ std::u16string ASCIIToUTF16(std::string src) {
|
||||
}
|
||||
|
||||
std::u16string UTF8ToUTF16(std::string src) {
|
||||
#if defined(_WIN32)
|
||||
return WideToUTF16(win::Utf16FromUtf8(src));
|
||||
#else
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
||||
return convert.from_bytes(src);
|
||||
#endif
|
||||
return fml::Utf8ToUtf16(src);
|
||||
}
|
||||
|
||||
std::string UTF16ToUTF8(std::u16string src) {
|
||||
#if defined(_WIN32)
|
||||
return win::Utf8FromUtf16(UTF16ToWide(src));
|
||||
#else
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
||||
return convert.to_bytes(src);
|
||||
#endif
|
||||
return fml::Utf16ToUtf8(src);
|
||||
}
|
||||
|
||||
std::u16string WideToUTF16(const std::wstring& src) {
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// TODO(gw280): This is copied from shell/platform/win. When
|
||||
// https://github.com/flutter/flutter/issues/75653 is fixed, we should
|
||||
// deduplicate these and put them in fml.
|
||||
#include "string_conversion.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
namespace base {
|
||||
namespace win {
|
||||
|
||||
std::string Utf8FromUtf16(const std::wstring& utf16_string) {
|
||||
if (utf16_string.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
int target_length = ::WideCharToMultiByte(
|
||||
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string.data(),
|
||||
static_cast<int>(utf16_string.length()), nullptr, 0, nullptr, nullptr);
|
||||
if (target_length == 0) {
|
||||
return std::string();
|
||||
}
|
||||
std::string utf8_string;
|
||||
utf8_string.resize(target_length);
|
||||
int converted_length = ::WideCharToMultiByte(
|
||||
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string.data(),
|
||||
static_cast<int>(utf16_string.length()), utf8_string.data(),
|
||||
target_length, nullptr, nullptr);
|
||||
if (converted_length == 0) {
|
||||
return std::string();
|
||||
}
|
||||
return utf8_string;
|
||||
}
|
||||
|
||||
std::wstring Utf16FromUtf8(const std::string& utf8_string) {
|
||||
if (utf8_string.empty()) {
|
||||
return std::wstring();
|
||||
}
|
||||
int target_length =
|
||||
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8_string.data(),
|
||||
static_cast<int>(utf8_string.length()), nullptr, 0);
|
||||
if (target_length == 0) {
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf16_string;
|
||||
utf16_string.resize(target_length);
|
||||
int converted_length =
|
||||
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8_string.data(),
|
||||
static_cast<int>(utf8_string.length()),
|
||||
utf16_string.data(), target_length);
|
||||
if (converted_length == 0) {
|
||||
return std::wstring();
|
||||
}
|
||||
return utf16_string;
|
||||
}
|
||||
|
||||
} // namespace win
|
||||
} // namespace base
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_STRING_CONVERSION_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_STRING_CONVERSION_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace base {
|
||||
namespace win {
|
||||
|
||||
// Converts a string from UTF-16 to UTF-8. Returns an empty string if the
|
||||
// input is not valid UTF-16.
|
||||
std::string Utf8FromUtf16(const std::wstring& utf16_string);
|
||||
|
||||
// Converts a string from UTF-8 to UTF-16. Returns an empty string if the
|
||||
// input is not valid UTF-8.
|
||||
std::wstring Utf16FromUtf8(const std::string& utf8_string);
|
||||
|
||||
} // namespace win
|
||||
} // namespace base
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_STRING_CONVERSION_H_
|
||||
Reference in New Issue
Block a user