Add an enumerable() method for loops.

This is a helper to aid in iterating over items.  This returns a list
of objects that contain:
- "item": The current value.
- "prev": The previous value in the list.
- "next": The next value in the list.
- "i": The zero-based index in the list.

Issue #1518

Change-Id: Id18ab977e3ae45dfbfd2b4137a1bffb6e53c6bce
This commit is contained in:
Jacob Trimble
2019-06-17 11:28:03 -07:00
parent 60d2f1cc82
commit 47533d1173
12 changed files with 154 additions and 55 deletions
+4 -2
View File
@@ -17,6 +17,7 @@
goog.provide('shaka.util.Uint8ArrayUtils');
goog.require('shaka.util.Iterables');
goog.require('shaka.util.StringUtils');
@@ -65,8 +66,9 @@ shaka.util.Uint8ArrayUtils = class {
// byte.
const bytes = window.atob(str.replace(/-/g, '+').replace(/_/g, '/'));
const result = new Uint8Array(bytes.length);
for (let i = 0; i < bytes.length; ++i) {
result[i] = bytes.charCodeAt(i);
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
for (const {i, item} of enumerate(bytes)) {
result[i] = item.charCodeAt(0);
}
return result;
}