Skip to content

Commit 0c19dae

Browse files
nex3devoncarew
andauthored
Add public access to a SourceFile's code units (dart-archive/source_span#93)
* 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]>
1 parent dd5ecf1 commit 0c19dae

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

pkgs/source_span/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## 1.9.2-dev
1+
## 1.10.0
22

3+
* Add a `SourceFile.codeUnits` property.
34
* Require Dart 2.18
45
* Add an API usage example in `example/`.
56

pkgs/source_span/lib/src/file.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ class SourceFile {
3232
/// the file.
3333
final _lineStarts = <int>[0];
3434

35-
/// The code points of the characters in the file.
35+
/// The code units of the characters in the file.
36+
///
37+
/// If this was constructed with the deprecated `SourceFile()` constructor,
38+
/// this will instead contain the code _points_ of the characters in the file
39+
/// (so characters above 2^16 are represented as individual integers rather
40+
/// than surrogate pairs).
41+
List<int> get codeUnits => _decodedChars;
42+
43+
/// The code units of the characters in this file.
3644
final Uint32List _decodedChars;
3745

3846
/// The length of the file in characters.

pkgs/source_span/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_span
2-
version: 1.9.2-dev
2+
version: 1.10.0
33
description: >-
44
Provides a standard representation for source code locations and spans.
55
repository: https://github.com/dart-lang/source_span

0 commit comments

Comments
 (0)