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