Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp

Issue 1824143003: [All-In-One] Introduce BackspaceStateMachine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to HEAD Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium 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 "core/editing/BackspaceStateMachine.h"
6
7 #include "third_party/icu/source/common/unicode/utf16.h"
8
9 namespace blink {
10
11 BackspaceStateMachine::BackspaceStateMachine()
yosin_UTC9 2016/03/28 05:05:47 nit: s/{}/= default/
Seigo Nonaka 2016/03/28 07:28:11 Done.
12 {
13 }
14
15 int BackspaceStateMachine::finalizeAndGetCodeUnitCountToBeDeleted()
16 {
17 if (m_trailSurrogate != 0) {
18 // Unpaired trail surrogate. Removing broken surrogate.
19 ++m_codeUnitsToBeDeleted;
20 m_trailSurrogate = 0;
21 }
22 return m_codeUnitsToBeDeleted;
23 }
24
25 bool BackspaceStateMachine::updateState(uint16_t codeUnit)
26 {
27 uint32_t codePoint = codeUnit;
28 if (U16_IS_LEAD(codeUnit)) {
29 if (m_trailSurrogate == 0) {
30 // Unpaired lead surrogate. Aborting with deleting broken surrogate.
31 ++m_codeUnitsToBeDeleted;
32 return true;
33 }
34 codePoint = U16_GET_SUPPLEMENTARY(codeUnit, m_trailSurrogate);
35 m_trailSurrogate = 0;
36 } else if (U16_IS_TRAIL(codeUnit)) {
37 if (m_trailSurrogate != 0) {
38 // Unpaired trail surrogate. Aborting with deleting broken
39 // surrogate.
40 return true;
41 }
42 m_trailSurrogate = codeUnit;
43 return false; // Needs surrogate lead.
44 } else {
45 if (m_trailSurrogate != 0) {
46 // Unpaired trail surrogate. Aborting with deleting broken
47 // surrogate.
48 return true;
49 }
50 }
51
52 // TODO(nona): Handle emoji sequences.
53 m_codeUnitsToBeDeleted = U16_LENGTH(codePoint);
54 return true;
55 }
56
57 void BackspaceStateMachine::reset()
58 {
59 m_codeUnitsToBeDeleted = 0;
60 m_trailSurrogate = 0;
61 }
62
63 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698