Skip to content

Commit 408f995

Browse files
authored
modernize the specification script (#2957)
Modernize the specification script `addlatexhash.dart` such that it works with Dart 3.0.
1 parent 4596fde commit 408f995

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

specification/pubspec.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: scripts
22
publish_to: none
33
environment:
4-
sdk: ">=2.10.0 <3.0.0"
5-
dependencies:
4+
sdk: ">=2.12.0 <3.0.0"
5+
dependencies:
66
convert: ^3.0.1
77
crypto: ^3.0.1
8-
utf: ^0.9.0+5

specification/scripts/addlatexhash.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
// NB: This utility assumes UN*X style line endings, \n, in the LaTeX
2323
// source file received as input; it will not work with other styles.
2424

25+
import 'dart:convert';
2526
import 'dart:io';
2627

2728
import 'package:crypto/crypto.dart';
2829
import 'package:convert/convert.dart';
29-
import 'package:utf/utf.dart';
3030

3131
// ----------------------------------------------------------------------
3232
// Normalization of the text: removal or normalization of parts that
@@ -40,7 +40,7 @@ final whitespaceRE = new RegExp(r"(?:(?=\s).){2,}"); // \s except end-of-line
4040
/// given [startOffset] and [endOffset], bounded to be valid indices
4141
/// into the string if needed, then inserts [glue] where text was
4242
/// removed. If there is no match then [line] is returned.
43-
cutMatch(line, match, {startOffset: 0, endOffset: 0, glue: ""}) {
43+
cutMatch(line, match, {startOffset = 0, endOffset = 0, glue = ""}) {
4444
if (match == null) return line;
4545
var start = match.start + startOffset;
4646
var end = match.end + endOffset;
@@ -50,20 +50,20 @@ cutMatch(line, match, {startOffset: 0, endOffset: 0, glue: ""}) {
5050
return line.substring(0, start) + glue + line.substring(end);
5151
}
5252

53-
cutRegexp(line, re, {startOffset: 0, endOffset: 0, glue: ""}) {
53+
cutRegexp(line, re, {startOffset = 0, endOffset = 0, glue = ""}) {
5454
return cutMatch(line, re.firstMatch(line),
5555
startOffset: startOffset, endOffset: endOffset, glue: glue);
5656
}
5757

5858
/// Removes the rest of [line] starting from the beginning of the
5959
/// given [match], and adjusting with the given [offset]. If there
6060
/// is no match then [line] is returned.
61-
cutFromMatch(line, match, {offset: 0, glue: ""}) {
61+
cutFromMatch(line, match, {offset = 0, glue = ""}) {
6262
if (match == null) return line;
6363
return line.substring(0, match.start + offset) + glue;
6464
}
6565

66-
cutFromRegexp(line, re, {offset: 0, glue: ""}) {
66+
cutFromRegexp(line, re, {offset = 0, glue = ""}) {
6767
return cutFromMatch(line, re.firstMatch(line), offset: offset, glue: glue);
6868
}
6969

@@ -242,8 +242,7 @@ bool isntHashBlockTerminator(line) => !isSectioningCommand(line);
242242
extractHashLabel(line) {
243243
var startMatch = hashLabelStartRE.firstMatch(line);
244244
var endMatch = hashLabelEndRE.firstMatch(line);
245-
assert(startMatch != null && endMatch != null);
246-
return line.substring(startMatch.end, endMatch.start);
245+
return line.substring(startMatch!.end, endMatch!.start);
247246
}
248247

249248
// Event classes: Keep track of relevant information about the LaTeX
@@ -491,7 +490,7 @@ computeHashValue(lines, startIndex, nextIndex, listSink) {
491490
final gatheredLine = gatherLines(lines, startIndex, nextIndex);
492491
final simplifiedLine = simplifyLine(gatheredLine);
493492
listSink.write(" % $simplifiedLine\n");
494-
var digest = sha1.convert(encodeUtf8(simplifiedLine));
493+
var digest = sha1.convert(utf8.encode(simplifiedLine));
495494
return digest.bytes;
496495
}
497496

0 commit comments

Comments
 (0)