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

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: Created 4 years, 9 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 <unicode/utf16.h>
8
9 namespace blink {
10
11 BackspaceStateMachine::BackspaceStateMachine()
12 : mCodeUnitsToBeDeleted(0)
13 , mTrailSurrogate(0)
14 {
15 }
16
17 int BackspaceStateMachine::FinalizeAndGetCodeUnitCountToBeDeleted()
18 {
19 if (mTrailSurrogate != 0) {
20 // Unpaired trail surrogate. Removing broken surrogate.
21 ++mCodeUnitsToBeDeleted;
yosin_UTC9 2016/03/25 04:37:23 It seems we should reset |mTrailSurogate| too.
Seigo Nonaka 2016/03/25 06:59:06 Done.
22 }
23 return mCodeUnitsToBeDeleted;
24 }
25
26 bool BackspaceStateMachine::ComputeNextState(uint16_t codeUnit)
yosin_UTC9 2016/03/25 04:37:22 |updateState()| or |moveToNextState()| or another?
Seigo Nonaka 2016/03/25 06:59:06 Sure, updated.
27 {
28 uint32_t cp = codeUnit;
yosin_UTC9 2016/03/25 04:37:23 s/cp/codePoint/
Seigo Nonaka 2016/03/25 06:59:06 Done.
29 if (U16_IS_LEAD(codeUnit)) {
30 if (mTrailSurrogate == 0) {
31 // Unpaired lead surrogate. Aborting with deleting broken surrogate.
32 ++mCodeUnitsToBeDeleted;
33 return true;
34 }
35 cp = U16_GET_SUPPLEMENTARY(codeUnit, mTrailSurrogate);
36 mTrailSurrogate = 0;
37 } else if (U16_IS_TRAIL(codeUnit)) {
38 if (mTrailSurrogate != 0) {
39 // Unpaired trail surrogate. Aborting with deleting broken
40 // surrogate.
41 ++mCodeUnitsToBeDeleted;
42 return true;
43 }
44 mTrailSurrogate = codeUnit;
45 return false; // Needs surrogate lead.
46 } else {
47 if (mTrailSurrogate != 0) {
48 // Unpaired trail surrogate. Aborting with deleting broken
49 // surrogate.
50 ++mCodeUnitsToBeDeleted;
51 return true;
52 }
53 }
54
55 // TODO(nona): Handle emoji sequences.
56 mCodeUnitsToBeDeleted = U16_LENGTH(cp);
57 return true;
58 }
59
60 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698