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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp
diff --git a/third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp b/third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d5fdb47584586b8b1cc364542749eba94d373271
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp
@@ -0,0 +1,60 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/BackspaceStateMachine.h"
+
+#include <unicode/utf16.h>
+
+namespace blink {
+
+BackspaceStateMachine::BackspaceStateMachine()
+ : mCodeUnitsToBeDeleted(0)
+ , mTrailSurrogate(0)
+{
+}
+
+int BackspaceStateMachine::FinalizeAndGetCodeUnitCountToBeDeleted()
+{
+ if (mTrailSurrogate != 0) {
+ // Unpaired trail surrogate. Removing broken surrogate.
+ ++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.
+ }
+ return mCodeUnitsToBeDeleted;
+}
+
+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.
+{
+ uint32_t cp = codeUnit;
yosin_UTC9 2016/03/25 04:37:23 s/cp/codePoint/
Seigo Nonaka 2016/03/25 06:59:06 Done.
+ if (U16_IS_LEAD(codeUnit)) {
+ if (mTrailSurrogate == 0) {
+ // Unpaired lead surrogate. Aborting with deleting broken surrogate.
+ ++mCodeUnitsToBeDeleted;
+ return true;
+ }
+ cp = U16_GET_SUPPLEMENTARY(codeUnit, mTrailSurrogate);
+ mTrailSurrogate = 0;
+ } else if (U16_IS_TRAIL(codeUnit)) {
+ if (mTrailSurrogate != 0) {
+ // Unpaired trail surrogate. Aborting with deleting broken
+ // surrogate.
+ ++mCodeUnitsToBeDeleted;
+ return true;
+ }
+ mTrailSurrogate = codeUnit;
+ return false; // Needs surrogate lead.
+ } else {
+ if (mTrailSurrogate != 0) {
+ // Unpaired trail surrogate. Aborting with deleting broken
+ // surrogate.
+ ++mCodeUnitsToBeDeleted;
+ return true;
+ }
+ }
+
+ // TODO(nona): Handle emoji sequences.
+ mCodeUnitsToBeDeleted = U16_LENGTH(cp);
+ return true;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698