This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Migrate string encoding conversions to FML #31334
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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. | ||
|
||
#include "flutter/fml/platform/win/wstring_conversion.h" | ||
|
||
#include <codecvt> | ||
#include <locale> | ||
#include <string> | ||
|
||
namespace fml { | ||
|
||
using WideStringConverter = | ||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>; | ||
|
||
std::string WideStringToUtf8(const std::wstring_view str) { | ||
WideStringConverter converter; | ||
return converter.to_bytes(str.data()); | ||
} | ||
|
||
std::wstring Utf8ToWideString(const std::string_view str) { | ||
WideStringConverter converter; | ||
return converter.from_bytes(str.data()); | ||
} | ||
|
||
} // namespace fml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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. | ||
|
||
#include "flutter/fml/platform/win/wstring_conversion.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace fml { | ||
namespace testing { | ||
|
||
TEST(StringConversion, Utf16ToWideStringEmpty) { | ||
EXPECT_EQ(Utf8ToWideString(""), L""); | ||
} | ||
|
||
TEST(StringConversion, Utf8ToWideStringAscii) { | ||
EXPECT_EQ(Utf8ToWideString("abc123"), L"abc123"); | ||
} | ||
|
||
TEST(StringConversion, Utf8ToWideStringUnicode) { | ||
EXPECT_EQ(Utf8ToWideString("\xe2\x98\x83"), L"\x2603"); | ||
} | ||
|
||
TEST(StringConversion, WideStringToUtf8Empty) { | ||
EXPECT_EQ(WideStringToUtf8(L""), ""); | ||
} | ||
|
||
TEST(StringConversion, WideStringToUtf8Ascii) { | ||
EXPECT_EQ(WideStringToUtf8(L"abc123"), "abc123"); | ||
} | ||
|
||
TEST(StringConversion, WideStringToUtf8Unicode) { | ||
EXPECT_EQ(WideStringToUtf8(L"\x2603"), "\xe2\x98\x83"); | ||
} | ||
|
||
} // namespace testing | ||
} // namespace fml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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. | ||
|
||
#include "flutter/fml/string_conversion.h" | ||
|
||
#include <codecvt> | ||
#include <locale> | ||
#include <string> | ||
|
||
#include "flutter/fml/build_config.h" | ||
|
||
#if defined(FML_OS_WIN) | ||
// TODO(naifu): https://github.com/flutter/flutter/issues/98074 | ||
// Eliminate this workaround for a link error on Windows when the underlying | ||
// bug is fixed. | ||
std::locale::id std::codecvt<char16_t, char, _Mbstatet>::id; | ||
#endif // defined(FML_OS_WIN) | ||
|
||
namespace fml { | ||
|
||
using Utf16StringConverter = | ||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>; | ||
|
||
std::string Utf16ToUtf8(const std::u16string_view string) { | ||
Utf16StringConverter converter; | ||
return converter.to_bytes(string.data()); | ||
} | ||
|
||
std::u16string Utf8ToUtf16(const std::string_view string) { | ||
Utf16StringConverter converter; | ||
return converter.from_bytes(string.data()); | ||
} | ||
|
||
} // namespace fml |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.