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

Unified Diff: third_party/WebKit/Source/core/editing/state_machines/BackwardCodePointStateMachine.cpp

Issue 2706713002: Introduce BackwardCodePointStateMachine to traverse chars in code points (Closed)
Patch Set: Created 3 years, 10 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/state_machines/BackwardCodePointStateMachine.cpp
diff --git a/third_party/WebKit/Source/core/editing/state_machines/BackwardCodePointStateMachine.cpp b/third_party/WebKit/Source/core/editing/state_machines/BackwardCodePointStateMachine.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..022aa03ad2643682269552429324f6bf01b60a17
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/state_machines/BackwardCodePointStateMachine.cpp
@@ -0,0 +1,69 @@
+// Copyright 2017 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/state_machines/BackwardCodePointStateMachine.h"
+
+namespace blink {
+
+enum class BackwardCodePointStateMachine::BackwardCodePointState {
+ NotSurrogate,
+ TrailSurrogate,
+ Invalid,
+};
+
+BackwardCodePointStateMachine::BackwardCodePointStateMachine()
+ : m_state(BackwardCodePointState::NotSurrogate) {}
+
+TextSegmentationMachineState
+BackwardCodePointStateMachine::feedPrecedingCodeUnit(UChar codeUnit) {
+ switch (m_state) {
+ case BackwardCodePointState::NotSurrogate:
+ if (U16_IS_LEAD(codeUnit)) {
+ m_codeUnitsToBeDeleted = 0;
+ m_state = BackwardCodePointState::Invalid;
+ return TextSegmentationMachineState::Invalid;
+ }
+ ++m_codeUnitsToBeDeleted;
+ if (U16_IS_TRAIL(codeUnit)) {
+ m_state = BackwardCodePointState::TrailSurrogate;
+ return TextSegmentationMachineState::NeedMoreCodeUnit;
+ }
+ return TextSegmentationMachineState::Finished;
+ case BackwardCodePointState::TrailSurrogate:
+ if (U16_IS_LEAD(codeUnit)) {
+ ++m_codeUnitsToBeDeleted;
+ m_state = BackwardCodePointState::NotSurrogate;
+ return TextSegmentationMachineState::Finished;
+ }
+ m_codeUnitsToBeDeleted = 0;
+ m_state = BackwardCodePointState::Invalid;
+ return TextSegmentationMachineState::Invalid;
+ case BackwardCodePointState::Invalid:
+ m_codeUnitsToBeDeleted = 0;
+ return TextSegmentationMachineState::Invalid;
+ }
+ NOTREACHED();
+ return TextSegmentationMachineState::Invalid;
+}
+
+TextSegmentationMachineState
+BackwardCodePointStateMachine::feedFollowingCodeUnit(UChar codeUnit) {
+ NOTREACHED();
+ return TextSegmentationMachineState::Invalid;
+}
+
+bool BackwardCodePointStateMachine::atCodePointBoundary() {
+ return m_state == BackwardCodePointState::NotSurrogate;
+}
+
+int BackwardCodePointStateMachine::getBoundaryOffset() {
+ return -m_codeUnitsToBeDeleted;
+}
+
+void BackwardCodePointStateMachine::reset() {
+ m_codeUnitsToBeDeleted = 0;
+ m_state = BackwardCodePointState::NotSurrogate;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698