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

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

Powered by Google App Engine
This is Rietveld 408576698