Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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/BackspaceStateMachine.h" | |
| 6 | |
| 7 #include <unicode/utf16.h> | |
|
yosin_UTC9
2016/03/25 10:01:05
nit: s/<unicode/utf16.h>/"third_party/icu/source/c
Seigo Nonaka
2016/03/25 10:26:32
Done and also updated DEPS.
| |
| 8 | |
| 9 namespace blink { | |
| 10 | |
| 11 BackspaceStateMachine::BackspaceStateMachine() | |
| 12 { | |
| 13 } | |
| 14 | |
| 15 int BackspaceStateMachine::finalizeAndGetCodeUnitCountToBeDeleted() | |
| 16 { | |
| 17 if (m_TrailSurrogate != 0) { | |
| 18 // Unpaired trail surrogate. Removing broken surrogate. | |
| 19 ++m_CodeUnitsToBeDeleted; | |
| 20 m_TrailSurrogate = 0; | |
| 21 } | |
| 22 return m_CodeUnitsToBeDeleted; | |
| 23 } | |
| 24 | |
| 25 bool BackspaceStateMachine::updateState(uint16_t codeUnit) | |
| 26 { | |
| 27 uint32_t codePoint = codeUnit; | |
| 28 if (U16_IS_LEAD(codeUnit)) { | |
| 29 if (m_TrailSurrogate == 0) { | |
| 30 // Unpaired lead surrogate. Aborting with deleting broken surrogate. | |
| 31 ++m_CodeUnitsToBeDeleted; | |
| 32 return true; | |
| 33 } | |
| 34 codePoint = U16_GET_SUPPLEMENTARY(codeUnit, m_TrailSurrogate); | |
| 35 m_TrailSurrogate = 0; | |
| 36 } else if (U16_IS_TRAIL(codeUnit)) { | |
| 37 if (m_TrailSurrogate != 0) { | |
| 38 // Unpaired trail surrogate. Aborting with deleting broken | |
| 39 // surrogate. | |
| 40 return true; | |
| 41 } | |
| 42 m_TrailSurrogate = codeUnit; | |
| 43 return false; // Needs surrogate lead. | |
| 44 } else { | |
| 45 if (m_TrailSurrogate != 0) { | |
| 46 // Unpaired trail surrogate. Aborting with deleting broken | |
| 47 // surrogate. | |
| 48 return true; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 // TODO(nona): Handle emoji sequences. | |
| 53 m_CodeUnitsToBeDeleted = U16_LENGTH(codePoint); | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 void BackspaceStateMachine::reset() | |
| 58 { | |
| 59 m_CodeUnitsToBeDeleted = 0; | |
| 60 m_TrailSurrogate = 0; | |
| 61 } | |
| 62 | |
| 63 } // namespace blink | |
| OLD | NEW |