diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 45901aa51c07e..d004764ca7ec7 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -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 diff --git a/third_party/accessibility/base/BUILD.gn b/third_party/accessibility/base/BUILD.gn index 0897fa07224b0..54b0a47af32ef 100644 --- a/third_party/accessibility/base/BUILD.gn +++ b/third_party/accessibility/base/BUILD.gn @@ -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", ] diff --git a/third_party/accessibility/base/string_utils.cc b/third_party/accessibility/base/string_utils.cc index 0152bbcbef65e..61e0a4a257f4a 100644 --- a/third_party/accessibility/base/string_utils.cc +++ b/third_party/accessibility/base/string_utils.cc @@ -11,12 +11,9 @@ #include #include +#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, 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, char16_t> convert; - return convert.to_bytes(src); -#endif + return fml::Utf16ToUtf8(src); } std::u16string WideToUTF16(const std::wstring& src) { diff --git a/third_party/accessibility/base/win/string_conversion.cc b/third_party/accessibility/base/win/string_conversion.cc deleted file mode 100644 index 15bff3ce7b17a..0000000000000 --- a/third_party/accessibility/base/win/string_conversion.cc +++ /dev/null @@ -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 - -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(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(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(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(utf8_string.length()), - utf16_string.data(), target_length); - if (converted_length == 0) { - return std::wstring(); - } - return utf16_string; -} - -} // namespace win -} // namespace base diff --git a/third_party/accessibility/base/win/string_conversion.h b/third_party/accessibility/base/win/string_conversion.h deleted file mode 100644 index 471268f4d046a..0000000000000 --- a/third_party/accessibility/base/win/string_conversion.h +++ /dev/null @@ -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 - -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_