44
55#include " flutter/shell/platform/common/cpp/text_input_model.h"
66
7+ #include < codecvt>
78#include < iostream>
9+ #include < locale>
810
911// TODO(awdavies): Need to fix this regarding issue #47.
1012static constexpr char kComposingBaseKey [] = " composingBase" ;
@@ -26,11 +28,16 @@ static constexpr char kTextInputAction[] = "inputAction";
2628static constexpr char kTextInputType [] = " inputType" ;
2729static constexpr char kTextInputTypeName [] = " name" ;
2830
31+ #if defined(_MSC_VER)
32+ // TODO(naifu): This temporary code is to solve link error.(VS2015/2017)
33+ // https://social.msdn.microsoft.com/Forums/vstudio/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error
34+ std::locale::id std::codecvt<char32_t , char , _Mbstatet>::id;
35+ #endif // defined(_MSC_VER)
36+
2937namespace flutter {
3038
3139TextInputModel::TextInputModel (int client_id, const rapidjson::Value& config)
32- : text_(" " ),
33- client_id_ (client_id),
40+ : client_id_(client_id),
3441 selection_base_ (text_.begin()),
3542 selection_extent_(text_.begin()) {
3643 // TODO: Improve error handling during refactoring; this is just minimal
@@ -64,7 +71,8 @@ bool TextInputModel::SetEditingState(size_t selection_base,
6471 if (selection_extent > text.size ()) {
6572 return false ;
6673 }
67- text_ = std::string (text);
74+ std::wstring_convert<std::codecvt_utf8<char32_t >, char32_t > utf32conv;
75+ text_ = utf32conv.from_bytes (text);
6876 selection_base_ = text_.begin () + selection_base;
6977 selection_extent_ = text_.begin () + selection_extent;
7078 return true ;
@@ -76,7 +84,7 @@ void TextInputModel::DeleteSelected() {
7684 selection_extent_ = selection_base_;
7785}
7886
79- void TextInputModel::AddCharacter (char c) {
87+ void TextInputModel::AddCharacter (char32_t c) {
8088 if (selection_base_ != selection_extent_) {
8189 DeleteSelected ();
8290 }
@@ -172,8 +180,10 @@ std::unique_ptr<rapidjson::Document> TextInputModel::GetState() const {
172180 static_cast <int >(selection_extent_ - text_.begin ()),
173181 allocator);
174182 editing_state.AddMember (kSelectionIsDirectionalKey , false , allocator);
175- editing_state.AddMember (kTextKey , rapidjson::Value (text_, allocator).Move (),
176- allocator);
183+ std::wstring_convert<std::codecvt_utf8<char32_t >, char32_t > utf8conv;
184+ editing_state.AddMember (
185+ kTextKey , rapidjson::Value (utf8conv.to_bytes (text_), allocator).Move (),
186+ allocator);
177187 args->PushBack (editing_state, allocator);
178188 return args;
179189}
0 commit comments