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

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

Issue 1884893002: Use WTF::String and WTF::Vector in state machine tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-13T14:42:37 Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/state_machines/StateMachineTestUtil.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/state_machines/StateMachineTestUtil.cpp
diff --git a/third_party/WebKit/Source/core/editing/state_machines/StateMachineTestUtil.cpp b/third_party/WebKit/Source/core/editing/state_machines/StateMachineTestUtil.cpp
index c009346d469bcd63fe4740bc0d3b412fb1f443b1..32851fd95865875cb2fad5d3bc7cb7f70d7ba89c 100644
--- a/third_party/WebKit/Source/core/editing/state_machines/StateMachineTestUtil.cpp
+++ b/third_party/WebKit/Source/core/editing/state_machines/StateMachineTestUtil.cpp
@@ -8,8 +8,8 @@
#include "core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h"
#include "core/editing/state_machines/TextSegmentationMachineState.h"
#include "wtf/Assertions.h"
+#include "wtf/text/StringBuilder.h"
#include <algorithm>
-#include <vector>
namespace blink {
@@ -28,87 +28,87 @@ char MachineStateToChar(TextSegmentationMachineState state)
return *it;
}
-std::vector<UChar> codePointsToCodeUnits(const std::vector<UChar32>& codePoints)
+Vector<UChar> codePointsToCodeUnits(const Vector<UChar32>& codePoints)
{
- std::vector<UChar> out;
+ Vector<UChar> out;
for (const auto& codePoint : codePoints) {
if (U16_LENGTH(codePoint) == 2) {
- out.push_back(U16_LEAD(codePoint));
- out.push_back(U16_TRAIL(codePoint));
+ out.append(U16_LEAD(codePoint));
+ out.append(U16_TRAIL(codePoint));
} else {
- out.push_back(static_cast<UChar>(codePoint));
+ out.append(static_cast<UChar>(codePoint));
}
}
return out;
}
template<typename StateMachine>
-std::string processSequence(StateMachine* machine,
- const std::vector<UChar32>& preceding,
- const std::vector<UChar32>& following)
+String processSequence(StateMachine* machine,
+ const Vector<UChar32>& preceding,
+ const Vector<UChar32>& following)
{
machine->reset();
- std::string out;
+ StringBuilder out;
TextSegmentationMachineState state = TextSegmentationMachineState::Invalid;
- std::vector<UChar> precedingCodeUnits = codePointsToCodeUnits(preceding);
+ Vector<UChar> precedingCodeUnits = codePointsToCodeUnits(preceding);
std::reverse(precedingCodeUnits.begin(), precedingCodeUnits.end());
for (const auto& codeUnit : precedingCodeUnits) {
state = machine->feedPrecedingCodeUnit(codeUnit);
- out += MachineStateToChar(state);
+ out.append(MachineStateToChar(state));
switch (state) {
case TextSegmentationMachineState::Invalid:
case TextSegmentationMachineState::Finished:
- return out;
+ return out.toString();
case TextSegmentationMachineState::NeedMoreCodeUnit:
continue;
case TextSegmentationMachineState::NeedFollowingCodeUnit:
break;
}
}
- if (preceding.empty()
+ if (preceding.isEmpty()
|| state == TextSegmentationMachineState::NeedMoreCodeUnit) {
state = machine->tellEndOfPrecedingText();
- out += MachineStateToChar(state);
+ out.append(MachineStateToChar(state));
}
if (state == TextSegmentationMachineState::Finished)
- return out;
+ return out.toString();
- std::vector<UChar> followingCodeUnits = codePointsToCodeUnits(following);
+ Vector<UChar> followingCodeUnits = codePointsToCodeUnits(following);
for (const auto& codeUnit : followingCodeUnits) {
state = machine->feedFollowingCodeUnit(codeUnit);
- out += MachineStateToChar(state);
+ out.append(MachineStateToChar(state));
switch (state) {
case TextSegmentationMachineState::Invalid:
case TextSegmentationMachineState::Finished:
- return out;
+ return out.toString();
case TextSegmentationMachineState::NeedMoreCodeUnit:
continue;
case TextSegmentationMachineState::NeedFollowingCodeUnit:
break;
}
}
- return out;
+ return out.toString();
}
} // namespace
-std::string processSequenceBackward(
+String GraphemeStateMachineTestBase::processSequenceBackward(
BackwardGraphemeBoundaryStateMachine* machine,
- const std::vector<UChar32>& preceding)
+ const Vector<UChar32>& preceding)
{
- const std::string& out =
- processSequence(machine, preceding, std::vector<UChar32>());
+ const String& out =
+ processSequence(machine, preceding, Vector<UChar32>());
if (machine->finalizeAndGetBoundaryOffset()
!= machine->finalizeAndGetBoundaryOffset())
return "State machine changes final offset after finished.";
return out;
}
-std::string processSequenceForward(
+String GraphemeStateMachineTestBase::processSequenceForward(
ForwardGraphemeBoundaryStateMachine* machine,
- const std::vector<UChar32>& preceding,
- const std::vector<UChar32>& following)
+ const Vector<UChar32>& preceding,
+ const Vector<UChar32>& following)
{
- const std::string& out = processSequence(machine, preceding, following);
+ const String& out = processSequence(machine, preceding, following);
if (machine->finalizeAndGetBoundaryOffset()
!= machine->finalizeAndGetBoundaryOffset())
return "State machine changes final offset after finished.";
« no previous file with comments | « third_party/WebKit/Source/core/editing/state_machines/StateMachineTestUtil.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698