Flutter Windows Embedder
keyboard_utils.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "keyboard_utils.h"
6 
7 #include "flutter/fml/logging.h"
8 
9 namespace flutter {
10 
11 std::u16string EncodeUtf16(char32_t character) {
12  // Algorithm: https://en.wikipedia.org/wiki/UTF-16#Description
13  std::u16string result;
14  // Invalid value.
15  FML_DCHECK(!(character >= 0xD800 && character <= 0xDFFF) &&
16  !(character > 0x10FFFF));
17  if ((character >= 0xD800 && character <= 0xDFFF) || (character > 0x10FFFF)) {
18  return result;
19  }
20  if (character <= 0xD7FF || (character >= 0xE000 && character <= 0xFFFF)) {
21  result.push_back((char16_t)character);
22  return result;
23  }
24  uint32_t remnant = character - 0x10000;
25  result.push_back((remnant >> 10) + 0xD800);
26  result.push_back((remnant & 0x3FF) + 0xDC00);
27  return result;
28 }
29 
30 } // namespace flutter
character
char32_t character
Definition: keyboard_key_handler_unittests.cc:117
flutter::EncodeUtf16
std::u16string EncodeUtf16(char32_t character)
Definition: keyboard_utils.cc:11
keyboard_utils.h
flutter
Definition: accessibility_bridge_windows.cc:11