mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-20 13:35:11 +08:00
This patch is part of the underscore migration that adds the private keyword to all properties that start with an underscore and removes the underscore. Bug:chromium:1207342 Change-Id: I956106361701d8c686a1e43e45ee9fb8d8c64a94 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3078239 Commit-Queue: Jan Scheffler <janscheffler@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Auto-Submit: Jan Scheffler <janscheffler@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as Platform from '../../core/platform/platform.js';
|
|
|
|
export class TextCursor {
|
|
private lineEndings: number[];
|
|
private offsetInternal: number;
|
|
private lineNumberInternal: number;
|
|
private columnNumberInternal: number;
|
|
|
|
constructor(lineEndings: number[]) {
|
|
this.lineEndings = lineEndings;
|
|
this.offsetInternal = 0;
|
|
this.lineNumberInternal = 0;
|
|
this.columnNumberInternal = 0;
|
|
}
|
|
|
|
advance(offset: number): void {
|
|
this.offsetInternal = offset;
|
|
while (this.lineNumberInternal < this.lineEndings.length &&
|
|
this.lineEndings[this.lineNumberInternal] < this.offsetInternal) {
|
|
++this.lineNumberInternal;
|
|
}
|
|
this.columnNumberInternal = this.lineNumberInternal ?
|
|
this.offsetInternal - this.lineEndings[this.lineNumberInternal - 1] - 1 :
|
|
this.offsetInternal;
|
|
}
|
|
|
|
offset(): number {
|
|
return this.offsetInternal;
|
|
}
|
|
|
|
resetTo(offset: number): void {
|
|
this.offsetInternal = offset;
|
|
this.lineNumberInternal =
|
|
Platform.ArrayUtilities.lowerBound(this.lineEndings, offset, Platform.ArrayUtilities.DEFAULT_COMPARATOR);
|
|
this.columnNumberInternal = this.lineNumberInternal ?
|
|
this.offsetInternal - this.lineEndings[this.lineNumberInternal - 1] - 1 :
|
|
this.offsetInternal;
|
|
}
|
|
|
|
lineNumber(): number {
|
|
return this.lineNumberInternal;
|
|
}
|
|
|
|
columnNumber(): number {
|
|
return this.columnNumberInternal;
|
|
}
|
|
}
|