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

Side by Side Diff: services/prediction/input_info.cc

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fixed build problem Created 5 years, 4 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 2015 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 <new>
6
7 #include "services/prediction/input_info.h"
8 #include "services/prediction/key_set.h"
9 #include "third_party/prediction/defines.h"
10
11 namespace prediction {
12
13 InputInfo::InputInfo() {
14 real_size_ = 0;
15 }
16
17 InputInfo::~InputInfo() {
18 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?
19 delete[] codepoints_;
20 delete[] x_coordinates_;
21 delete[] y_coordinates_;
22 delete[] pointer_ids_;
23 delete[] times_;
24 }
25 }
26
27 int* InputInfo::GetCodepoints() {
28 return codepoints_;
29 }
30
31 int* InputInfo::GetXCoordinates() {
32 return x_coordinates_;
33 }
34
35 int* InputInfo::GetYCoordinates() {
36 return y_coordinates_;
37 }
38
39 int* InputInfo::GetPointerIds() {
40 return pointer_ids_;
41 }
42
43 int* InputInfo::GetTimes() {
44 return times_;
45 }
46
47 int InputInfo::GetRealSize() {
48 return real_size_;
49 }
50
51 void InputInfo::ProcessInput(mojo::String& input) {
52 int input_size = std::min((int)input.size(), MAX_WORD_LENGTH);
53 real_size_ = 0;
54 for (int i = 0; i < input_size; i++) {
55 int codepoint = (int)input[i];
56 if ((codepoint >= 'a' && codepoint <= 'z') ||
57 (codepoint >= 'A' && codepoint <= 'Z')) {
58 real_size_++;
59 }
60 }
61
62 codepoints_ = new int[real_size_];
63 x_coordinates_ = new int[real_size_];
64 y_coordinates_ = new int[real_size_];
65 pointer_ids_ = new int[real_size_];
66 times_ = new int[real_size_];
67 int real_index = 0;
68 for (int i = 0; i < input_size; i++) {
69 int codepoint = (int)input[i];
70 if ((codepoint >= 'a' && codepoint <= 'z') ||
71 (codepoint >= 'A' && codepoint <= 'Z')) {
72 codepoints_[real_index] = codepoint;
73 for (int j = 0; j < keyset::key_count; j++) {
74 if (keyset::key_set[j].kcode == tolower(codepoint)) {
75 x_coordinates_[real_index] =
76 keyset::key_set[j].kx + keyset::key_set[j].kwidth / 2;
77 y_coordinates_[real_index] =
78 keyset::key_set[j].ky + keyset::key_set[j].kheight / 2;
79 break;
80 }
81 }
82 pointer_ids_[real_index] = 0;
83 times_[real_index] = 0;
84 real_index++;
85 }
86 }
87 }
88
89 } // namespace prediction
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698