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

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

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.h
diff --git a/third_party/WebKit/Source/core/editing/state_machines/BackwardCodePointStateMachine.h b/third_party/WebKit/Source/core/editing/state_machines/BackwardCodePointStateMachine.h
new file mode 100644
index 0000000000000000000000000000000000000000..502517188fd96b79c0c2b6da1baf74d61e43115a
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/state_machines/BackwardCodePointStateMachine.h
@@ -0,0 +1,52 @@
+// 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.
+
+#ifndef BackwardCodePointStateMachine_h
+#define BackwardCodePointStateMachine_h
+
+#include "core/CoreExport.h"
+#include "core/editing/state_machines/TextSegmentationMachineState.h"
+#include "wtf/Allocator.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/text/Unicode.h"
+
+namespace blink {
+
+class CORE_EXPORT BackwardCodePointStateMachine {
+ STACK_ALLOCATED();
+ WTF_MAKE_NONCOPYABLE(BackwardCodePointStateMachine);
+
+ public:
+ BackwardCodePointStateMachine();
+ ~BackwardCodePointStateMachine() = default;
+
+ // Prepares by feeding preceding text.
+ TextSegmentationMachineState feedPrecedingCodeUnit(UChar codeUnit);
+
+ // Finds boundary offset by feeding following text.
+ TextSegmentationMachineState feedFollowingCodeUnit(UChar codeUnit);
+
+ // Returns true if we are at code point boundary.
+ bool atCodePointBoundary();
+
+ // Returns the next boundary offset.
+ int getBoundaryOffset();
+
+ // Resets the internal state to the initial state.
+ void reset();
+
+ private:
+ enum class BackwardCodePointState;
+
+ // The number of code units to be deleted.
+ // Nothing to delete if there is an invalid surrogate pair.
+ int m_codeUnitsToBeDeleted = 0;
+
+ // The internal state.
+ BackwardCodePointState m_state;
+};
+
+} // namespace blink
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698