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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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/state_machines/ForwardCodePointStateMachine.h"
6
7 namespace blink {
8
9 enum class ForwardCodePointStateMachine::ForwardCodePointState {
10 NotSurrogate,
11 LeadSurrogate,
12 Invalid,
13 };
14
15 ForwardCodePointStateMachine::ForwardCodePointStateMachine()
16 : m_state(ForwardCodePointState::NotSurrogate) {}
17
18 TextSegmentationMachineState
19 ForwardCodePointStateMachine::feedFollowingCodeUnit(UChar codeUnit) {
20 switch (m_state) {
21 case ForwardCodePointState::NotSurrogate:
22 if (U16_IS_TRAIL(codeUnit)) {
23 m_codeUnitsToBeDeleted = 0;
24 m_state = ForwardCodePointState::Invalid;
25 return TextSegmentationMachineState::Invalid;
26 }
27 ++m_codeUnitsToBeDeleted;
28 if (U16_IS_LEAD(codeUnit)) {
29 m_state = ForwardCodePointState::LeadSurrogate;
30 return TextSegmentationMachineState::NeedMoreCodeUnit;
31 }
32 return TextSegmentationMachineState::Finished;
33 case ForwardCodePointState::LeadSurrogate:
34 if (U16_IS_TRAIL(codeUnit)) {
35 ++m_codeUnitsToBeDeleted;
36 m_state = ForwardCodePointState::NotSurrogate;
37 return TextSegmentationMachineState::Finished;
38 }
39 m_codeUnitsToBeDeleted = 0;
40 m_state = ForwardCodePointState::Invalid;
41 return TextSegmentationMachineState::Invalid;
42 case ForwardCodePointState::Invalid:
43 m_codeUnitsToBeDeleted = 0;
44 return TextSegmentationMachineState::Invalid;
45 }
46 NOTREACHED();
47 return TextSegmentationMachineState::Invalid;
48 }
49
50 TextSegmentationMachineState
51 ForwardCodePointStateMachine::feedPrecedingCodeUnit(UChar codeUnit) {
52 NOTREACHED();
53 return TextSegmentationMachineState::Invalid;
54 }
55
56 bool ForwardCodePointStateMachine::atCodePointBoundary() {
57 return m_state == ForwardCodePointState::NotSurrogate;
58 }
59
60 int ForwardCodePointStateMachine::getBoundaryOffset() {
61 return m_codeUnitsToBeDeleted;
62 }
63
64 void ForwardCodePointStateMachine::reset() {
65 m_codeUnitsToBeDeleted = 0;
66 m_state = ForwardCodePointState::NotSurrogate;
67 }
68
69 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698