| Index: tracing/tracing/importer/simple_line_reader.html
|
| diff --git a/tracing/tracing/importer/simple_line_reader.html b/tracing/tracing/importer/simple_line_reader.html
|
| index 636c9e88585a58534928378811ad399703399432..2fea194a68c4001f93096f42539123fd194d1798 100644
|
| --- a/tracing/tracing/importer/simple_line_reader.html
|
| +++ b/tracing/tracing/importer/simple_line_reader.html
|
| @@ -9,42 +9,75 @@ found in the LICENSE file.
|
| 'use strict';
|
|
|
| tr.exportTo('tr.importer', function() {
|
| - /**
|
| - * @constructor
|
| - */
|
| - function SimpleLineReader(text) {
|
| - this.lines_ = text.split('\n');
|
| - this.curLine_ = 0;
|
| -
|
| - this.savedLines_ = undefined;
|
| - }
|
| + class SimpleLineReader {
|
| + constructor(text) {
|
| + this.data_ = text instanceof tr.b.TraceStream ? text : text.split('\n');
|
| + this.curLine_ = 0;
|
| + this.readLastLine_ = false;
|
| + this.savedLines_ = undefined;
|
| + }
|
|
|
| - SimpleLineReader.prototype = {
|
| - advanceToLineMatching: function(regex) {
|
| - for (; this.curLine_ < this.lines_.length; this.curLine_++) {
|
| - var line = this.lines_[this.curLine_];
|
| - if (this.savedLines_ !== undefined) {
|
| - this.savedLines_.push(line);
|
| + * [Symbol.iterator]() {
|
| + let lastLine = undefined;
|
| + while (this.hasData_) {
|
| + if (this.readLastLine_) {
|
| + this.curLine_++;
|
| + this.readLastLine_ = false;
|
| + } else if (this.data_ instanceof tr.b.TraceStream) {
|
| + this.curLine_++;
|
| + let line = this.data_.readUntilDelimiter('\n');
|
| + lastLine = line.endsWith('\n') ? line.slice(0, -1) : line;
|
| + } else {
|
| + this.curLine_++;
|
| + lastLine = this.data_[this.curLine_ - 1];
|
| }
|
| - if (regex.test(line)) return true;
|
| + yield lastLine;
|
| }
|
| - return false;
|
| - },
|
| + }
|
|
|
| get curLineNumber() {
|
| return this.curLine_;
|
| - },
|
| + }
|
| +
|
| + get hasData_() {
|
| + if (this.data_ instanceof tr.b.TraceStream) return this.data_.hasData;
|
| + return this.curLine_ < this.data_.length;
|
| + }
|
| +
|
| + advanceToLineMatching(regex) {
|
| + for (const line of this) {
|
| + if (this.savedLines_ !== undefined) this.savedLines_.push(line);
|
| + if (regex.test(line)) {
|
| + this.goBack_();
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + goBack_() {
|
| + if (this.readLastLine_) {
|
| + throw new Error('There should be at least one nextLine call between ' +
|
| + 'any two goBack calls.');
|
| + }
|
| + if (this.curLine_ === 0) {
|
| + throw new Error('There should be at least one nextLine call before ' +
|
| + 'the first goBack call.');
|
| + }
|
| + this.readLastLine_ = true;
|
| + this.curLine_--;
|
| + }
|
|
|
| - beginSavingLines: function() {
|
| + beginSavingLines() {
|
| this.savedLines_ = [];
|
| - },
|
| + }
|
|
|
| - endSavingLinesAndGetResult: function() {
|
| + endSavingLinesAndGetResult() {
|
| var tmp = this.savedLines_;
|
| this.savedLines_ = undefined;
|
| return tmp;
|
| }
|
| - };
|
| + }
|
|
|
| return {
|
| SimpleLineReader,
|
|
|