OLD | NEW |
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. | 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. |
2 // limitations under the License. | 2 // limitations under the License. |
3 // See the License for the specific language governing permissions and | 3 // See the License for the specific language governing permissions and |
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
5 // distributed under the License is distributed on an "AS-IS" BASIS, | 5 // distributed under the License is distributed on an "AS-IS" BASIS, |
6 // Unless required by applicable law or agreed to in writing, software | 6 // Unless required by applicable law or agreed to in writing, software |
7 // | 7 // |
8 // http://www.apache.org/licenses/LICENSE-2.0 | 8 // http://www.apache.org/licenses/LICENSE-2.0 |
9 // | 9 // |
10 // You may obtain a copy of the License at | 10 // You may obtain a copy of the License at |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 * Returns the configuration file name from the keyboard code. | 322 * Returns the configuration file name from the keyboard code. |
323 * | 323 * |
324 * @param {string} keyboardCode The keyboard code. | 324 * @param {string} keyboardCode The keyboard code. |
325 * @return {string} The config file name which contains the keyset. | 325 * @return {string} The config file name which contains the keyset. |
326 */ | 326 */ |
327 util.getConfigName = function(keyboardCode) { | 327 util.getConfigName = function(keyboardCode) { |
328 // Strips out all the suffixes in the keyboard code. | 328 // Strips out all the suffixes in the keyboard code. |
329 return keyboardCode.replace(/\..*$/, ''); | 329 return keyboardCode.replace(/\..*$/, ''); |
330 }; | 330 }; |
331 | 331 |
| 332 |
| 333 /** |
| 334 * Checks that the word is a valid delete from the old to new context. |
| 335 * |
| 336 * @param {string} oldContext The old context. |
| 337 * @param {string} newContext The new context. |
| 338 * @param {string} deletionCandidate A possible word deletion. |
| 339 * |
| 340 * @return {boolean} Whether the deletion was valid. |
| 341 */ |
| 342 util.isPossibleDelete = function( |
| 343 oldContext, newContext, deletionCandidate) { |
| 344 // Check that deletionCandidate exists in oldContext. We don't check if it's a |
| 345 // tail since our heuristic may have trimmed whitespace. |
| 346 var rootEnd = oldContext.lastIndexOf(deletionCandidate); |
| 347 if (rootEnd != -1) { |
| 348 // Check that remaining text in root persisted in newContext. |
| 349 var root = oldContext.slice(0, rootEnd); |
| 350 return root == newContext.slice(-rootEnd); |
| 351 } |
| 352 return false; |
| 353 }; |
| 354 |
| 355 |
| 356 /** |
| 357 * Checks whether a letter deletion would cause the observed context transform. |
| 358 * |
| 359 * @param {string} oldContext The old context. |
| 360 * @param {string} newContext The new context. |
| 361 * |
| 362 * @return {boolean} Whether the transform is valid. |
| 363 */ |
| 364 util.isLetterDelete = function(oldContext, newContext) { |
| 365 if (oldContext == '') { |
| 366 return false; |
| 367 } |
| 368 // Handle buffer overflow. |
| 369 if (oldContext.length == newContext.length) { |
| 370 return util.isLetterDelete(oldContext, newContext.slice(1)); |
| 371 } |
| 372 return oldContext.length == newContext.length + 1 && |
| 373 oldContext.indexOf(newContext) == 0; |
| 374 }; |
| 375 |
| 376 |
| 377 /** |
| 378 * Checks whether a letter restoration would cause the observed context |
| 379 * transform. |
| 380 * |
| 381 * @param {string} oldContext The old context. |
| 382 * @param {string} newContext The new context. |
| 383 * |
| 384 * @return {boolean} Whether the transform is valid. |
| 385 */ |
| 386 util.isLetterRestore = function(oldContext, newContext) { |
| 387 return util.isLetterDelete(newContext, oldContext); |
| 388 }; |
| 389 |
332 }); // goog.scope | 390 }); // goog.scope |
OLD | NEW |