| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <deque> | 6 #include <deque> |
| 7 #include <fstream> | 7 #include <fstream> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 it != suggestion_words_reverse.end(); ++it) { | 165 it != suggestion_words_reverse.end(); ++it) { |
| 166 suggestion_words.push_back(mojo::String(*it)); | 166 suggestion_words.push_back(mojo::String(*it)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 return suggestion_words.Clone().Pass(); | 169 return suggestion_words.Clone().Pass(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 // modified from Android JniDataUtils::constructPrevWordsInfo | 172 // modified from Android JniDataUtils::constructPrevWordsInfo |
| 173 latinime::PrevWordsInfo DictionaryService::ProcessPrevWord( | 173 latinime::PrevWordsInfo DictionaryService::ProcessPrevWord( |
| 174 mojo::Array<PrevWordInfoPtr>& prev_words) { | 174 mojo::Array<PrevWordInfoPtr>& prev_words) { |
| 175 int prev_word_codepoints[MAX_PREV_WORD_COUNT_FOR_N_GRAM][MAX_WORD_LENGTH]; | 175 int prev_word_codepoints[MAX_PREV_WORD_COUNT_FOR_N_GRAM][MAX_WORD_LENGTH] = { |
| 176 int prev_word_codepoint_count[MAX_PREV_WORD_COUNT_FOR_N_GRAM]; | 176 {0}}; |
| 177 bool are_beginning_of_sentence[MAX_PREV_WORD_COUNT_FOR_N_GRAM]; | 177 int prev_word_codepoint_count[MAX_PREV_WORD_COUNT_FOR_N_GRAM] = {0}; |
| 178 bool are_beginning_of_sentence[MAX_PREV_WORD_COUNT_FOR_N_GRAM] = {false}; |
| 178 int prevwords_count = std::min( | 179 int prevwords_count = std::min( |
| 179 prev_words.size(), static_cast<size_t>(MAX_PREV_WORD_COUNT_FOR_N_GRAM)); | 180 prev_words.size(), static_cast<size_t>(MAX_PREV_WORD_COUNT_FOR_N_GRAM)); |
| 180 for (int i = 0; i < prevwords_count; ++i) { | 181 for (int i = 0; i < prevwords_count; ++i) { |
| 181 prev_word_codepoint_count[i] = 0; | 182 prev_word_codepoint_count[i] = 0; |
| 182 are_beginning_of_sentence[i] = false; | 183 are_beginning_of_sentence[i] = false; |
| 183 int prev_word_size = prev_words[i]->word.size(); | 184 int prev_word_size = prev_words[i]->word.size(); |
| 184 if (prev_word_size > MAX_WORD_LENGTH) { | 185 if (prev_word_size > MAX_WORD_LENGTH) { |
| 185 continue; | 186 continue; |
| 186 } | 187 } |
| 187 for (int j = 0; j < prev_word_size; j++) { | 188 for (int j = 0; j < prev_word_size; j++) { |
| 188 prev_word_codepoints[i][j] = (int)((prev_words[i])->word)[j]; | 189 prev_word_codepoints[i][j] = (int)((prev_words[i])->word)[j]; |
| 189 } | 190 } |
| 190 prev_word_codepoint_count[i] = prev_word_size; | 191 prev_word_codepoint_count[i] = prev_word_size; |
| 191 are_beginning_of_sentence[i] = prev_words[i]->is_beginning_of_sentence; | 192 are_beginning_of_sentence[i] = prev_words[i]->is_beginning_of_sentence; |
| 192 } | 193 } |
| 193 latinime::PrevWordsInfo prev_words_info = | 194 latinime::PrevWordsInfo prev_words_info = |
| 194 latinime::PrevWordsInfo(prev_word_codepoints, prev_word_codepoint_count, | 195 latinime::PrevWordsInfo(prev_word_codepoints, prev_word_codepoint_count, |
| 195 are_beginning_of_sentence, prevwords_count); | 196 are_beginning_of_sentence, prevwords_count); |
| 196 return prev_words_info; | 197 return prev_words_info; |
| 197 } | 198 } |
| 198 | 199 |
| 199 } // namespace prediction | 200 } // namespace prediction |
| OLD | NEW |