Skip to content

Commit

Permalink
Add public access to a SourceFile's code units (dart-lang/source_span#93
Browse files Browse the repository at this point in the history
)

* Add public access to a SourceFile's code units

This makes it possible to efficiently reparse information from around
a `FileSpan`, such as to expand it through surrounding whitespace
characters. Otherwise, a caller would have to call `getText()` which
can be very expensive in a tight loop.

* Fix lints

* Update CHANGELOG.md

Co-authored-by: Devon Carew <[email protected]>

---------

Co-authored-by: Devon Carew <[email protected]>
  • Loading branch information
nex3 and devoncarew authored Apr 5, 2023
1 parent dd5ecf1 commit 0c19dae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkgs/source_span/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.9.2-dev
## 1.10.0

* Add a `SourceFile.codeUnits` property.
* Require Dart 2.18
* Add an API usage example in `example/`.

Expand Down
10 changes: 9 additions & 1 deletion pkgs/source_span/lib/src/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ class SourceFile {
/// the file.
final _lineStarts = <int>[0];

/// The code points of the characters in the file.
/// The code units of the characters in the file.
///
/// If this was constructed with the deprecated `SourceFile()` constructor,
/// this will instead contain the code _points_ of the characters in the file
/// (so characters above 2^16 are represented as individual integers rather
/// than surrogate pairs).
List<int> get codeUnits => _decodedChars;

/// The code units of the characters in this file.
final Uint32List _decodedChars;

/// The length of the file in characters.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/source_span/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: source_span
version: 1.9.2-dev
version: 1.10.0
description: >-
Provides a standard representation for source code locations and spans.
repository: https://github.com/dart-lang/source_span
Expand Down

0 comments on commit 0c19dae

Please sign in to comment.