Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

merge null_safety branch into master #28

Merged
merged 4 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
language: dart
dart:
- dev
- stable
# Only building master means that we don't run two builds for each pull request.
dart_task:
- test: --platform vm,chrome
- dartanalyzer
- dartfmt

jobs:
include:
- stage: analyze_and_format
name: "Analyze lib/ (no experiment flag)"
dart: dev
os: linux
script: dartanalyzer --fatal-warnings --fatal-infos lib/
- stage: analyze_and_format
name: "Analyze (with experiment flag)"
dart: dev
os: linux
script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos .
- stage: analyze_and_format
name: "Format"
dart: dev
os: linux
script: dartfmt -n --set-exit-if-changed .
- stage: test
name: "Vm Tests"
dart: dev
os: linux
script: pub run --enable-experiment=non-nullable test -p vm
- stage: test
name: "Web Tests"
dart: dev
os: linux
script: pub run --enable-experiment=non-nullable test -p chrome

branches:
only: [master]
only: [master, null_safety]

cache:
directories:
- $HOME/.pub-cache
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.0-nullsafety

* Make package null safe.

## 1.0.0

* Core APIs deemed stable; package version set to 1.0.0.
Expand Down
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ analyzer:
annotate_overrides: ignore
prefer_single_quotes: ignore
use_function_type_syntax_for_parameters: ignore
enable-experiment:
- non-nullable
23 changes: 12 additions & 11 deletions lib/src/characters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ abstract class Characters implements Iterable<String> {
/// as well as controlling the iteration in more detail.
CharacterRange get iteratorAtEnd;

/// Whether [Character] is an element of this sequence of
/// characters.
/// Whether [other] is an element of this sequence of
/// others.
///
/// Returns false if [Character] is not a string containing
/// Returns false if [other] is not a string containing
/// a single character,
/// because then it is not a single element of this [Iterable]
/// of characters.
bool contains(Object Character);
bool contains(Object? other);

/// Whether this sequence of characters contains [other]
/// as a subsequence.
Expand All @@ -79,13 +79,14 @@ abstract class Characters implements Iterable<String> {
/// Returns a [CharacterRange] containing the first occurrence of
/// [characters] in this string.
/// Returns `null` if there is no such occurrence.
CharacterRange /*?*/ findFirst(Characters characters);
CharacterRange? findFirst(Characters characters);

/// Finds the last occurrence of [characters].
///
/// Returns a [CharacterRange] containing the last occurrence of
/// [characters]. Returns `null` if there is no such occurrence,
CharacterRange /*?*/ findLast(Characters characters);
/// [characters].
/// Returns `null` if there is no such occurrence,
CharacterRange? findLast(Characters characters);

/// Eagerly selects a subset of the characters.
///
Expand Down Expand Up @@ -132,7 +133,7 @@ abstract class Characters implements Iterable<String> {
/// of characters.
Characters skipWhile(bool Function(String) test);

/// Eagerly selects a leading sequnce of characters.
/// Eagerly selects a leading sequence of characters.
///
/// Checks each character, from first to last, against [test],
/// until one is found whwere [test] returns `false`.
Expand All @@ -143,7 +144,7 @@ abstract class Characters implements Iterable<String> {
/// is returned.
Characters takeWhile(bool Function(String) test);

/// Eagerly selects a leading sequnce of characters.
/// Eagerly selects a leading sequence of characters.
///
/// Checks each character, from last to first, against [test],
/// until one is found whwere [test] returns `false`.
Expand Down Expand Up @@ -679,7 +680,7 @@ abstract class CharacterRange implements Iterator<String> {
///
/// Returns `null` if there are no occurrences of [pattern]
/// in the current range.
CharacterRange /*?*/ replaceAll(Characters pattern, Characters replacement);
CharacterRange? replaceAll(Characters pattern, Characters replacement);

/// Splits the current range of characters at each occurrence of [pattern].
///
Expand Down Expand Up @@ -737,7 +738,7 @@ abstract class CharacterRange implements Iterator<String> {
///
/// Returns `null` if there are no occurrences of [pattern]
/// in the current range.
CharacterRange /*?*/ replaceFirst(Characters pattern, Characters replacement);
CharacterRange? replaceFirst(Characters pattern, Characters replacement);

/// Whether the current range starts with [characters].
///
Expand Down
19 changes: 9 additions & 10 deletions lib/src/characters_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class StringCharacters extends Iterable<String> implements Characters {

@override
Iterable<T> whereType<T>() {
Iterable<Object> self = this;
Iterable<Object?> self = this;
if (self is Iterable<T>) {
return self.map<T>((x) => x);
}
Expand All @@ -83,7 +83,7 @@ class StringCharacters extends Iterable<String> implements Characters {
}

@override
String lastWhere(bool test(String element), {String orElse()}) {
String lastWhere(bool test(String element), {String orElse()?}) {
int cursor = string.length;
var brk = BackBreaks(string, cursor, 0, stateEoTNoBreak);
int next = 0;
Expand Down Expand Up @@ -114,7 +114,7 @@ class StringCharacters extends Iterable<String> implements Characters {
}

@override
bool contains(Object other) {
bool contains(Object? other) {
if (other is String) {
if (other.isEmpty) return false;
int next = Breaks(other, 0, other.length, stateSoTNoBreak).nextBreak();
Expand Down Expand Up @@ -375,14 +375,14 @@ class StringCharacters extends Iterable<String> implements Characters {
String toString() => string;

@override
CharacterRange findFirst(Characters characters) {
CharacterRange? findFirst(Characters characters) {
var range = _rangeAll;
if (range.collapseToFirst(characters)) return range;
return null;
}

@override
CharacterRange findLast(Characters characters) {
CharacterRange? findLast(Characters characters) {
var range = _rangeAll;
if (range.collapseToLast(characters)) return range;
return null;
Expand All @@ -408,7 +408,7 @@ class StringCharacterRange implements CharacterRange {

/// The [current] value is created lazily and cached to avoid repeated
/// or unnecessary string allocation.
String _currentCache;
String? _currentCache;

StringCharacterRange(String string) : this._(string, 0, 0);
StringCharacterRange._(this._string, this._start, this._end);
Expand Down Expand Up @@ -778,8 +778,7 @@ class StringCharacterRange implements CharacterRange {
}

@override
CharacterRange /*?*/ replaceFirst(
Characters pattern, Characters replacement) {
CharacterRange? replaceFirst(Characters pattern, Characters replacement) {
String patternString = pattern.string;
String replacementString = replacement.string;
String replaced;
Expand All @@ -799,7 +798,7 @@ class StringCharacterRange implements CharacterRange {
}

@override
CharacterRange /*?*/ replaceAll(Characters pattern, Characters replacement) {
CharacterRange? replaceAll(Characters pattern, Characters replacement) {
var patternString = pattern.string;
var replacementString = replacement.string;
if (patternString.isEmpty) {
Expand All @@ -811,7 +810,7 @@ class StringCharacterRange implements CharacterRange {
if (_start == _end) return null;
int start = 0;
int cursor = _start;
StringBuffer buffer;
StringBuffer? buffer;
while ((cursor = _indexOf(_string, patternString, cursor, _end)) >= 0) {
(buffer ??= StringBuffer())
..write(_string.substring(start, cursor))
Expand Down
90 changes: 88 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,96 @@
name: characters
version: 1.0.0
version: 1.1.0-nullsafety
description: String replacement with operations that are Unicode/grapheme cluster aware.
homepage: https://www.github.com/dart-lang/characters

environment:
sdk: ">=2.6.0 <3.0.0"
# This must remain a tight constraint (only allow dev versions) until nnbd is
# stable.
sdk: '>=2.9.0-18.0 <2.9.0'

dev_dependencies:
test: "^1.6.0"
pedantic: ^1.9.0

dependency_overrides:
async:
git:
url: git://github.com/dart-lang/async.git
ref: null_safety
boolean_selector:
git:
url: git://github.com/dart-lang/boolean_selector.git
ref: null_safety
charcode:
git:
url: git://github.com/dart-lang/charcode.git
ref: null_safety
collection:
git: git://github.com/dart-lang/collection.git
js:
git:
url: git://github.com/dart-lang/sdk.git
path: pkg/js
matcher:
git:
url: git://github.com/dart-lang/matcher.git
ref: null_safety
meta:
git:
url: git://github.com/dart-lang/sdk.git
path: pkg/meta
path:
git:
url: git://github.com/dart-lang/path.git
ref: null_safety
pedantic:
git:
url: git://github.com/dart-lang/pedantic.git
ref: null_safety
pool:
git:
url: git://github.com/dart-lang/pool.git
ref: null_safety
source_maps:
git:
url: git://github.com/dart-lang/source_maps.git
ref: null_safety
source_map_stack_trace:
git:
url: git://github.com/dart-lang/source_map_stack_trace.git
ref: null_safety
source_span:
git:
url: git://github.com/dart-lang/source_span.git
ref: null_safety
stack_trace:
git:
url: git://github.com/dart-lang/stack_trace.git
ref: null_safety
stream_channel:
git:
url: git://github.com/dart-lang/stream_channel.git
ref: null_safety
string_scanner:
git:
url: git://github.com/dart-lang/string_scanner.git
ref: null_safety
term_glyph:
git:
url: git://github.com/dart-lang/term_glyph.git
ref: null_safety
test_api:
git:
url: git://github.com/dart-lang/test.git
ref: null_safety
path: pkgs/test_api
test_core:
git:
url: git://github.com/dart-lang/test.git
ref: null_safety
path: pkgs/test_core
test:
git:
url: git://github.com/dart-lang/test.git
ref: null_safety
path: pkgs/test
Loading