Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
9namespace flutter {
10
11std::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
GAsyncResult * result
#define FML_DCHECK(condition)
Definition logging.h:103
std::u16string EncodeUtf16(char32_t character)