| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @fileoverview General utility functions for rule stores. | 6 * @fileoverview General utility functions for rule stores. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('cvox.StoreUtil'); | 9 goog.provide('cvox.StoreUtil'); |
| 10 | 10 |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Count list of nodes and concatenate this with the context string. | 13 * Count list of nodes and concatenate this with the context string. |
| 14 * Returns a closure with a local state. | 14 * Returns a closure with a local state. |
| 15 * @param {Array.<Node>} nodes A node array. | 15 * @param {Array<Node>} nodes A node array. |
| 16 * @param {?string} context A context string. | 16 * @param {?string} context A context string. |
| 17 * @return {function(): string} A function returning a string. | 17 * @return {function(): string} A function returning a string. |
| 18 */ | 18 */ |
| 19 cvox.StoreUtil.nodeCounter = function(nodes, context) { | 19 cvox.StoreUtil.nodeCounter = function(nodes, context) { |
| 20 // Local state. | 20 // Local state. |
| 21 var localLength = nodes.length; | 21 var localLength = nodes.length; |
| 22 var localCounter = 0; | 22 var localCounter = 0; |
| 23 var localContext = context; | 23 var localContext = context; |
| 24 if (!context) { | 24 if (!context) { |
| 25 localContext = ''; | 25 localContext = ''; |
| 26 } | 26 } |
| 27 return function() { | 27 return function() { |
| 28 if (localCounter < localLength) { | 28 if (localCounter < localLength) { |
| 29 localCounter += 1; | 29 localCounter += 1; |
| 30 } | 30 } |
| 31 return localContext + ' ' + localCounter; | 31 return localContext + ' ' + localCounter; |
| 32 }; | 32 }; |
| 33 }; | 33 }; |
| OLD | NEW |