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

Add extension method for easy creation #11

Merged
merged 5 commits into from
Nov 13, 2019
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: dart
dart:
- dev
- 2.5.0
- stable
# Only building master means that we don't run two builds for each pull request.
dart_task:
- test: --platform vm,chrome
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.4.0

* Added an extension method on `String` to allow easy access to the `Characters`
of the string:

```dart
print('The first character is: ' + myString.characters.first)
```

* Updated Dart SDK dependency to Dart 2.6.0

## 0.3.1

* Added small example in `example/main.dart`
Expand Down
10 changes: 7 additions & 3 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ main() {

// Length.
print('String.length: ${hi.length}');
print('Characters.length: ${Characters(hi).length}\n');
print('Characters.length: ${hi.characters.length}\n');

// Last character.
print('The string ends with: ${hi.substring(hi.length - 1)}');
print('The last character: ${hi.characters.last}\n');

// Skip last character.
print('String.substring: "${hi.substring(0, hi.length - 1)}"');
print('Characters.skipLast: "${Characters(hi).skipLast(1)}"\n');
print('Substring -1: "${hi.substring(0, hi.length - 1)}"');
print('Skipping last character: "${hi.characters.skipLast(1)}"\n');

// Replace characters.
Characters newHi =
Expand Down
1 change: 1 addition & 0 deletions lib/characters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
library characters;

export "src/characters.dart";
export "src/extensions.dart";
10 changes: 10 additions & 0 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'characters.dart';
mit-mit marked this conversation as resolved.
Show resolved Hide resolved

extension StringCharacters on String {
/// The [Characters] of this string.
Characters get characters => Characters(this);
}
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: characters
version: 0.3.1
version: 0.4.0
description: String replacement with operations that are Unicode/grapheme cluster aware.
author: Dart Team <misc@dartlang.org>
homepage: https://www.github.com/dart-lang/characters

environment:
sdk: ">=2.5.0 <3.0.0"
sdk: ">=2.6.0 <3.0.0"
dev_dependencies:
test: "^1.6.0"
pedantic: