Skip to content

Commit

Permalink
Merge pull request #134 from dart-lang/merge-convert-package
Browse files Browse the repository at this point in the history
Merge `package:convert`
  • Loading branch information
mosuem authored Oct 16, 2024
2 parents 17d1b2c + cbf9a16 commit 16f396f
Show file tree
Hide file tree
Showing 35 changed files with 3,136 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- changed-files:
- any-glob-to-any-file: 'pkgs/args/**'

"package:convert":
- changed-files:
- any-glob-to-any-file: 'pkgs/convert/**'

"package:crypto":
- changed-files:
- any-glob-to-any-file: 'pkgs/crypto/**'
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/convert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: package:convert

on:
# Run CI on pushes to the main branch, and on PRs against main.
push:
branches: [ main ]
paths:
- '.github/workflows/convert.yaml'
- 'pkgs/convert/**'
pull_request:
branches: [ main ]
paths:
- '.github/workflows/convert.yaml'
- 'pkgs/convert/**'
schedule:
- cron: "0 0 * * 0"
env:
PUB_ENVIRONMENT: bot.github

defaults:
run:
working-directory: pkgs/convert/

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release sdk: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.4, dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests
run: dart test --platform chrome
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests - wasm
run: dart test --platform chrome --compiler dart2wasm
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This repository is home to various Dart packages under the [dart.dev](https://pu
| Package | Description | Version |
|---|---|---|
| [args](pkgs/args/) | Library for defining parsers for parsing raw command-line arguments into a set of options and values. | [![pub package](https://img.shields.io/pub/v/args.svg)](https://pub.dev/packages/args) |
| [convert](pkgs/convert/) | Utilities for converting between data representations. | [![pub package](https://img.shields.io/pub/v/convert.svg)](https://pub.dev/packages/convert) |
| [crypto](pkgs/crypto/) | Implementations of SHA, MD5, and HMAC cryptographic functions. | [![pub package](https://img.shields.io/pub/v/crypto.svg)](https://pub.dev/packages/crypto) |
| [fixnum](pkgs/fixnum/) | Library for 32- and 64-bit signed fixed-width integers. | [![pub package](https://img.shields.io/pub/v/fixnum.svg)](https://pub.dev/packages/fixnum) |

Expand Down
3 changes: 3 additions & 0 deletions pkgs/convert/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dart_tool
.packages
pubspec.lock
6 changes: 6 additions & 0 deletions pkgs/convert/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Below is a list of people and organizations that have contributed
# to the project. Names should be added to the list like so:
#
# Name/Organization <email address>

Google Inc.
75 changes: 75 additions & 0 deletions pkgs/convert/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
## 3.1.2

- Require Dart 3.4
- Add chunked decoding support (`startChunkedConversion`) for `CodePage`
encodings.
- Upper-cast the return type of the decoder from `List<int>` to `Uint8List`.
- Move to `dart-lang/core` monorepo.

## 3.1.1

- Require Dart 2.18
- Fix a number of comment references.

## 3.1.0

- Add a fixed-pattern DateTime formatter. See
[#210](https://github.com/dart-lang/intl/issues/210) in package:intl.

## 3.0.2

- Fix bug in `CodePage` class. See issue
[#47](https://github.com/dart-lang/convert/issues/47).

## 3.0.1

- Dependency clean-up.

## 3.0.0

- Stable null safety release.
- Added `CodePage` class for single-byte `Encoding` implementations.

## 2.1.1

- Fixed a DDC compilation regression for consumers using the Dart 1.x SDK that
was introduced in `2.1.0`.

## 2.1.0

- Added an `IdentityCodec<T>` which implements `Codec<T,T>` for use as default
value for in functions accepting an optional `Codec` as parameter.

## 2.0.2

- Set max SDK version to `<3.0.0`, and adjust other dependencies.

## 2.0.1

- `PercentEncoder` no longer encodes digits. This follows the specified
behavior.

## 2.0.0

**Note**: No new APIs have been added in 2.0.0. Packages that would use 2.0.0 as
a lower bound should use 1.0.0 instead—for example, `convert: ">=1.0.0 <3.0.0"`.

- `HexDecoder`, `HexEncoder`, `PercentDecoder`, and `PercentEncoder` no longer
extend `ChunkedConverter`.

## 1.1.1

- Fix all strong-mode warnings.

## 1.1.0

- Add `AccumulatorSink`, `ByteAccumulatorSink`, and `StringAccumulatorSink`
classes for providing synchronous access to the output of chunked converters.

## 1.0.1

- Small improvement in percent decoder efficiency.

## 1.0.0

- Initial version
27 changes: 27 additions & 0 deletions pkgs/convert/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2015, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 changes: 9 additions & 0 deletions pkgs/convert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[![Dart CI](https://github.com/dart-lang/core/actions/workflows/convert.yaml/badge.svg)](https://github.com/dart-lang/core/actions/workflows/convert.yaml)
[![pub package](https://img.shields.io/pub/v/convert.svg)](https://pub.dev/packages/convert)
[![package publisher](https://img.shields.io/pub/publisher/convert.svg)](https://pub.dev/packages/convert/publisher)

Contains encoders and decoders for converting between different
data representations. It's the external counterpart of the
[`dart:convert`](https://api.dart.dev/dart-convert/dart-convert-library.html)
SDK library, and contains less-central APIs and APIs that need more flexible
versioning.
24 changes: 24 additions & 0 deletions pkgs/convert/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# https://dart.dev/guides/language/analysis-options
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-raw-types: true

linter:
rules:
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_unused_constructor_parameters
- avoid_void_async
- cancel_subscriptions
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- package_api_docs
- prefer_const_declarations
- prefer_expression_function_bodies
- unnecessary_await_in_return
- use_string_buffers
23 changes: 23 additions & 0 deletions pkgs/convert/benchmark/fixed_datetime_formatter_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2022, 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 'package:benchmark_harness/benchmark_harness.dart';
import 'package:convert/convert.dart';

/// Test the performance of [FixedDateTimeFormatter.decode].
class DecodeBenchmark extends BenchmarkBase {
final fixedDateTimeFormatter = FixedDateTimeFormatter('YYYYMMDDhhmmss');
DecodeBenchmark() : super('Parse 10k strings to DateTime');

@override
void run() {
for (var i = 0; i < 10000; i++) {
fixedDateTimeFormatter.decode('19960425050322');
}
}
}

void main() {
DecodeBenchmark().report();
}
20 changes: 20 additions & 0 deletions pkgs/convert/example/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2020, 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 'dart:convert';

import 'package:convert/convert.dart';

void main(List<String> args) {
// Creates a Codec that converts a UTF-8 strings to/from percent encoding
final fusedCodec = utf8.fuse(percent);

final input = args.isNotEmpty ? args.first : 'ABC 123 @!(';
print(input);
final encodedMessage = fusedCodec.encode(input);
print(encodedMessage);

final decodedMessage = fusedCodec.decode(encodedMessage);
assert(decodedMessage == input);
}
12 changes: 12 additions & 0 deletions pkgs/convert/lib/convert.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2015, 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.

export 'src/accumulator_sink.dart';
export 'src/byte_accumulator_sink.dart';
export 'src/codepage.dart';
export 'src/fixed_datetime_formatter.dart';
export 'src/hex.dart';
export 'src/identity_codec.dart';
export 'src/percent.dart';
export 'src/string_accumulator_sink.dart';
40 changes: 40 additions & 0 deletions pkgs/convert/lib/src/accumulator_sink.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2016, 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 'dart:collection';
import 'dart:convert';

/// A sink that provides access to all the [events] that have been passed to it.
///
/// See also [ChunkedConversionSink.withCallback].
class AccumulatorSink<T> implements Sink<T> {
/// An unmodifiable list of events passed to this sink so far.
List<T> get events => UnmodifiableListView(_events);
final _events = <T>[];

/// Whether [close] has been called.
bool get isClosed => _isClosed;
var _isClosed = false;

/// Removes all events from [events].
///
/// This can be used to avoid double-processing events.
void clear() {
_events.clear();
}

@override
void add(T event) {
if (_isClosed) {
throw StateError("Can't add to a closed sink.");
}

_events.add(event);
}

@override
void close() {
_isClosed = true;
}
}
Loading

0 comments on commit 16f396f

Please sign in to comment.