Chromium Code Reviews| Index: services/prediction/input_info.cc |
| diff --git a/services/prediction/input_info.cc b/services/prediction/input_info.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3f13a29a5695ef63a373b79cba4efcd1e628dfab |
| --- /dev/null |
| +++ b/services/prediction/input_info.cc |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2015 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. |
| + |
| +#include <new> |
| + |
| +#include "services/prediction/input_info.h" |
| +#include "services/prediction/key_set.h" |
| +#include "third_party/prediction/defines.h" |
| + |
| +namespace prediction { |
| + |
| +InputInfo::InputInfo() { |
| + real_size_ = 0; |
| +} |
| + |
| +InputInfo::~InputInfo() { |
| + if (real_size_ > 0) { |
|
APW
2015/08/03 17:26:21
this won't work in all cases.
If real_size_ is 0
riajiang
2015/08/03 19:39:42
Moved array initialization to the constructor?
|
| + delete[] codepoints_; |
| + delete[] x_coordinates_; |
| + delete[] y_coordinates_; |
| + delete[] pointer_ids_; |
| + delete[] times_; |
| + } |
| +} |
| + |
| +int* InputInfo::GetCodepoints() { |
| + return codepoints_; |
| +} |
| + |
| +int* InputInfo::GetXCoordinates() { |
| + return x_coordinates_; |
| +} |
| + |
| +int* InputInfo::GetYCoordinates() { |
| + return y_coordinates_; |
| +} |
| + |
| +int* InputInfo::GetPointerIds() { |
| + return pointer_ids_; |
| +} |
| + |
| +int* InputInfo::GetTimes() { |
| + return times_; |
| +} |
| + |
| +int InputInfo::GetRealSize() { |
| + return real_size_; |
| +} |
| + |
| +void InputInfo::ProcessInput(mojo::String& input) { |
| + int input_size = std::min((int)input.size(), MAX_WORD_LENGTH); |
| + real_size_ = 0; |
| + for (int i = 0; i < input_size; i++) { |
| + int codepoint = (int)input[i]; |
| + if ((codepoint >= 'a' && codepoint <= 'z') || |
| + (codepoint >= 'A' && codepoint <= 'Z')) { |
| + real_size_++; |
| + } |
| + } |
| + |
| + codepoints_ = new int[real_size_]; |
| + x_coordinates_ = new int[real_size_]; |
| + y_coordinates_ = new int[real_size_]; |
| + pointer_ids_ = new int[real_size_]; |
| + times_ = new int[real_size_]; |
| + int real_index = 0; |
| + for (int i = 0; i < input_size; i++) { |
| + int codepoint = (int)input[i]; |
| + if ((codepoint >= 'a' && codepoint <= 'z') || |
| + (codepoint >= 'A' && codepoint <= 'Z')) { |
| + codepoints_[real_index] = codepoint; |
| + for (int j = 0; j < keyset::key_count; j++) { |
| + if (keyset::key_set[j].kcode == tolower(codepoint)) { |
| + x_coordinates_[real_index] = |
| + keyset::key_set[j].kx + keyset::key_set[j].kwidth / 2; |
| + y_coordinates_[real_index] = |
| + keyset::key_set[j].ky + keyset::key_set[j].kheight / 2; |
| + break; |
| + } |
| + } |
| + pointer_ids_[real_index] = 0; |
| + times_[real_index] = 0; |
| + real_index++; |
| + } |
| + } |
| +} |
| + |
| +} // namespace prediction |