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

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

Issue 2708523002: Introduce ForwardCodePointStateMachine 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/ForwardCodePointStateMachine.cpp
diff --git a/third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachine.cpp b/third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachine.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..aba73a24a6af58b4822ff621a57522ecb782de15
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachine.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/ForwardCodePointStateMachine.h"
+
+namespace blink {
+
+enum class ForwardCodePointStateMachine::ForwardCodePointState {
+ NotSurrogate,
+ LeadSurrogate,
+ Invalid,
+};
+
+ForwardCodePointStateMachine::ForwardCodePointStateMachine()
+ : m_state(ForwardCodePointState::NotSurrogate) {}
+
+TextSegmentationMachineState
+ForwardCodePointStateMachine::feedFollowingCodeUnit(UChar codeUnit) {
+ switch (m_state) {
+ case ForwardCodePointState::NotSurrogate:
+ if (U16_IS_TRAIL(codeUnit)) {
+ m_codeUnitsToBeDeleted = 0;
+ m_state = ForwardCodePointState::Invalid;
+ return TextSegmentationMachineState::Invalid;
+ }
+ ++m_codeUnitsToBeDeleted;
+ if (U16_IS_LEAD(codeUnit)) {
+ m_state = ForwardCodePointState::LeadSurrogate;
+ return TextSegmentationMachineState::NeedMoreCodeUnit;
+ }
+ return TextSegmentationMachineState::Finished;
+ case ForwardCodePointState::LeadSurrogate:
+ if (U16_IS_TRAIL(codeUnit)) {
+ ++m_codeUnitsToBeDeleted;
+ m_state = ForwardCodePointState::NotSurrogate;
+ return TextSegmentationMachineState::Finished;
+ }
+ m_codeUnitsToBeDeleted = 0;
+ m_state = ForwardCodePointState::Invalid;
+ return TextSegmentationMachineState::Invalid;
+ case ForwardCodePointState::Invalid:
+ m_codeUnitsToBeDeleted = 0;
+ return TextSegmentationMachineState::Invalid;
+ }
+ NOTREACHED();
+ return TextSegmentationMachineState::Invalid;
+}
+
+TextSegmentationMachineState
+ForwardCodePointStateMachine::feedPrecedingCodeUnit(UChar codeUnit) {
+ NOTREACHED();
+ return TextSegmentationMachineState::Invalid;
+}
+
+bool ForwardCodePointStateMachine::atCodePointBoundary() {
+ return m_state == ForwardCodePointState::NotSurrogate;
+}
+
+int ForwardCodePointStateMachine::getBoundaryOffset() {
+ return m_codeUnitsToBeDeleted;
+}
+
+void ForwardCodePointStateMachine::reset() {
+ m_codeUnitsToBeDeleted = 0;
+ m_state = ForwardCodePointState::NotSurrogate;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698