Remove dart:codec and move classes into dart:convert.
R=sgjesse@google.com Review URL: https://codereview.chromium.org//19941002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25267 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -38,10 +38,6 @@ static bootstrap_lib_props bootstrap_libraries[] = {
|
||||
async,
|
||||
Bootstrap::async_source_paths_,
|
||||
Bootstrap::async_patch_paths_),
|
||||
INIT_LIBRARY(ObjectStore::kCodec,
|
||||
codec,
|
||||
Bootstrap::codec_source_paths_,
|
||||
NULL),
|
||||
INIT_LIBRARY(ObjectStore::kConvert,
|
||||
convert,
|
||||
Bootstrap::convert_source_paths_,
|
||||
|
||||
@@ -19,7 +19,6 @@ class Bootstrap : public AllStatic {
|
||||
|
||||
// Source path mapping for library URI and 'parts'.
|
||||
static const char* async_source_paths_[];
|
||||
static const char* codec_source_paths_[];
|
||||
static const char* corelib_source_paths_[];
|
||||
static const char* collection_source_paths_[];
|
||||
static const char* collection_dev_source_paths_[];
|
||||
|
||||
@@ -22,7 +22,6 @@ class ObjectStore {
|
||||
enum {
|
||||
kNone = 0,
|
||||
kAsync,
|
||||
kCodec,
|
||||
kCore,
|
||||
kCollection,
|
||||
kCollectionDev,
|
||||
@@ -260,7 +259,6 @@ class ObjectStore {
|
||||
|
||||
RawLibrary* async_library() const { return async_library_; }
|
||||
RawLibrary* builtin_library() const { return builtin_library_; }
|
||||
RawLibrary* codec_library() const { return codec_library_; }
|
||||
RawLibrary* core_library() const { return core_library_; }
|
||||
RawLibrary* collection_library() const { return collection_library_; }
|
||||
RawLibrary* collection_dev_library() const {
|
||||
@@ -278,9 +276,6 @@ class ObjectStore {
|
||||
case kAsync:
|
||||
async_library_ = value.raw();
|
||||
break;
|
||||
case kCodec:
|
||||
codec_library_ = value.raw();
|
||||
break;
|
||||
case kCore:
|
||||
core_library_ = value.raw();
|
||||
break;
|
||||
@@ -464,7 +459,6 @@ class ObjectStore {
|
||||
RawArray* canonical_type_arguments_;
|
||||
RawLibrary* async_library_;
|
||||
RawLibrary* builtin_library_;
|
||||
RawLibrary* codec_library_;
|
||||
RawLibrary* core_library_;
|
||||
RawLibrary* collection_library_;
|
||||
RawLibrary* collection_dev_library_;
|
||||
|
||||
@@ -253,7 +253,6 @@ class ObjectPointerVisitor;
|
||||
V(DartSchemePrivate, "dart:_") \
|
||||
V(DartNativeWrappers, "dart:nativewrappers") \
|
||||
V(DartAsync, "dart:async") \
|
||||
V(DartCodec, "dart:codec") \
|
||||
V(DartCore, "dart:core") \
|
||||
V(DartCollection, "dart:collection") \
|
||||
V(DartCollectionDev, "dart:_collection-dev") \
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
'async_patch_cc_file': '<(gen_source_dir)/async_patch_gen.cc',
|
||||
'corelib_cc_file': '<(gen_source_dir)/corelib_gen.cc',
|
||||
'corelib_patch_cc_file': '<(gen_source_dir)/corelib_patch_gen.cc',
|
||||
'codec_cc_file': '<(gen_source_dir)/codec_gen.cc',
|
||||
'collection_cc_file': '<(gen_source_dir)/collection_gen.cc',
|
||||
'collection_patch_cc_file': '<(gen_source_dir)/collection_patch_gen.cc',
|
||||
'collection_dev_cc_file': '<(gen_source_dir)/collection_dev_gen.cc',
|
||||
@@ -97,7 +96,6 @@
|
||||
'dependencies': [
|
||||
'generate_async_cc_file#host',
|
||||
'generate_async_patch_cc_file#host',
|
||||
'generate_codec_cc_file#host',
|
||||
'generate_corelib_cc_file#host',
|
||||
'generate_corelib_patch_cc_file#host',
|
||||
'generate_collection_cc_file#host',
|
||||
@@ -131,7 +129,6 @@
|
||||
# Include generated source files.
|
||||
'<(async_cc_file)',
|
||||
'<(async_patch_cc_file)',
|
||||
'<(codec_cc_file)',
|
||||
'<(corelib_cc_file)',
|
||||
'<(corelib_patch_cc_file)',
|
||||
'<(collection_cc_file)',
|
||||
@@ -334,46 +331,6 @@
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
'target_name': 'generate_codec_cc_file',
|
||||
'type': 'none',
|
||||
'toolsets':['host'],
|
||||
'includes': [
|
||||
# Load the shared codec library sources.
|
||||
'../../sdk/lib/codec/codec_sources.gypi',
|
||||
],
|
||||
'sources/': [
|
||||
# Exclude all .[cc|h] files.
|
||||
# This is only here for reference. Excludes happen after
|
||||
# variable expansion, so the script has to do its own
|
||||
# exclude processing of the sources being passed.
|
||||
['exclude', '\\.cc|h$'],
|
||||
],
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'generate_codec_cc',
|
||||
'inputs': [
|
||||
'../tools/gen_library_src_paths.py',
|
||||
'<(libgen_in_cc_file)',
|
||||
'<@(_sources)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(codec_cc_file)',
|
||||
],
|
||||
'action': [
|
||||
'python',
|
||||
'tools/gen_library_src_paths.py',
|
||||
'--output', '<(codec_cc_file)',
|
||||
'--input_cc', '<(libgen_in_cc_file)',
|
||||
'--include', 'vm/bootstrap.h',
|
||||
'--var_name', 'dart::Bootstrap::codec_source_paths_',
|
||||
'--library_name', 'dart:codec',
|
||||
'<@(_sources)',
|
||||
],
|
||||
'message': 'Generating ''<(codec_cc_file)'' file.'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
'target_name': 'generate_collection_dev_patch_cc_file',
|
||||
'type': 'none',
|
||||
|
||||
@@ -30,9 +30,6 @@ const Map<String, LibraryInfo> LIBRARIES = const {
|
||||
"chrome/dart2js/chrome_dart2js.dart",
|
||||
category: "Client"),
|
||||
|
||||
"codec": const LibraryInfo(
|
||||
"codec/codec.dart"),
|
||||
|
||||
"collection": const LibraryInfo(
|
||||
"collection/collection.dart",
|
||||
dart2jsPatchPath: "_internal/lib/collection_patch.dart"),
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# Copyright (c) 2013, 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.
|
||||
|
||||
# This file contains all sources for the dart:convert library.
|
||||
{
|
||||
'sources': [
|
||||
'codec.dart',
|
||||
# The above file needs to be first as it lists the parts below.
|
||||
'json.dart',
|
||||
'encoding.dart',
|
||||
],
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright (c) 2013, 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.
|
||||
|
||||
part of dart.codec;
|
||||
|
||||
/**
|
||||
* Open-ended Encoding enum.
|
||||
*/
|
||||
// TODO(floitsch): dart:io already has an Encoding class. If we can't
|
||||
// consolitate them, we need to remove `Encoding` here.
|
||||
abstract class Encoding extends Codec<String, List<int>> {
|
||||
const Encoding();
|
||||
}
|
||||
|
||||
// TODO(floitsch): add other encodings, like ASCII and ISO_8859_1.
|
||||
const UTF8 = const Utf8Codec();
|
||||
|
||||
/**
|
||||
* A [Utf8Codec] encodes strings to utf-8 code units (bytes) and decodes
|
||||
* UTF-8 code units to strings.
|
||||
*/
|
||||
class Utf8Codec extends Encoding {
|
||||
final bool _allowMalformed;
|
||||
|
||||
/**
|
||||
* Instantiates a new [Utf8Codec].
|
||||
*
|
||||
* The optional [allowMalformed] argument defines how [decoder] (and [decode])
|
||||
* deal with invalid or unterminated character sequences.
|
||||
*
|
||||
* If it is `true` (and not overriden at the method invocation) [decode] and
|
||||
* the [decoder] replace invalid (or unterminated) octet
|
||||
* sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise
|
||||
* they throw a [FormatException].
|
||||
*/
|
||||
const Utf8Codec({ bool allowMalformed: false })
|
||||
: _allowMalformed = allowMalformed;
|
||||
|
||||
/**
|
||||
* Decodes the UTF-8 [codeUnits] (a list of unsigned 8-bit integers) to the
|
||||
* corresponding string.
|
||||
*
|
||||
* If [allowMalformed] is `true` the decoder replaces invalid (or
|
||||
* unterminated) character sequences with the Unicode Replacement character
|
||||
* `U+FFFD` (�). Otherwise it throws a [FormatException].
|
||||
*
|
||||
* If [allowMalformed] is not given, it defaults to the `allowMalformed` that
|
||||
* was used to instantiate `this`.
|
||||
*/
|
||||
String decode(List<int> codeUnits, { bool allowMalformed }) {
|
||||
if (allowMalformed == null) allowMalformed = _allowMalformed;
|
||||
return new Utf8Decoder(allowMalformed: allowMalformed).convert(codeUnits);
|
||||
}
|
||||
|
||||
Converter<String, List<int>> get encoder => new Utf8Encoder();
|
||||
Converter<List<int>, String> get decoder {
|
||||
return new Utf8Decoder(allowMalformed: _allowMalformed);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2013, 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.
|
||||
|
||||
part of dart.codec;
|
||||
|
||||
final JSON = new JsonCodec();
|
||||
|
||||
/**
|
||||
* A [JsonCodec] encodes JSON objects to strings and decodes strings to
|
||||
* JSON objects.
|
||||
*/
|
||||
class JsonCodec extends Codec<Object, String> {
|
||||
const JsonCodec();
|
||||
|
||||
/**
|
||||
* Creates a `JsonCodec` with the given reviver.
|
||||
*
|
||||
* The [reviver] function is called once for each object or list property
|
||||
* that has been parsed during decoding. The `key` argument is either the
|
||||
* integer list index for a list property, the map string for object
|
||||
* properties, or `null` for the final result.
|
||||
*/
|
||||
factory JsonCodec.withReviver(reviver(var key, var value)) =
|
||||
_ReviverJsonCodec;
|
||||
|
||||
/**
|
||||
* Parses the string and returns the resulting Json object.
|
||||
*
|
||||
* The optional [reviver] function, if provided, is called once for each
|
||||
* object or list property parsed.
|
||||
*/
|
||||
Object decode(String str, {reviver(var key, var value)}) {
|
||||
return new JsonDecoder(reviver).convert(str);
|
||||
}
|
||||
|
||||
JsonEncoder get encoder => new JsonEncoder();
|
||||
JsonDecoder get decoder => new JsonDecoder(null);
|
||||
}
|
||||
|
||||
class _ReviverJsonCodec extends JsonCodec {
|
||||
final Function _reviver;
|
||||
_ReviverJsonCodec(this._reviver);
|
||||
|
||||
Object decode(String str, {reviver(var key, var value)}) {
|
||||
if (reviver == null) reviver = _reviver;
|
||||
return new JsonDecoder(reviver).convert(str);
|
||||
}
|
||||
|
||||
JsonDecoder get decoder => new JsonDecoder(_reviver);
|
||||
}
|
||||
@@ -2,12 +2,7 @@
|
||||
// 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.
|
||||
|
||||
library dart.codec;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
part 'encoding.dart';
|
||||
part 'json.dart';
|
||||
part of dart.convert;
|
||||
|
||||
/**
|
||||
* A [Codec] encodes and (if supported) decodes data.
|
||||
@@ -7,6 +7,8 @@ library dart.convert;
|
||||
import 'dart:json' as OLD_JSON_LIB;
|
||||
import 'dart:utf' as OLD_UTF_LIB;
|
||||
|
||||
part 'codec.dart';
|
||||
part 'converter.dart';
|
||||
part 'encoding.dart';
|
||||
part 'json.dart';
|
||||
part 'utf.dart';
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
'sources': [
|
||||
'convert.dart',
|
||||
# The above file needs to be first as it lists the parts below.
|
||||
'codec.dart',
|
||||
'converter.dart',
|
||||
'encoding.dart',
|
||||
'json.dart',
|
||||
'utf.dart',
|
||||
],
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2013, 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.
|
||||
|
||||
part of dart.convert;
|
||||
|
||||
/**
|
||||
* Open-ended Encoding enum.
|
||||
*/
|
||||
// TODO(floitsch): dart:io already has an Encoding class. If we can't
|
||||
// consolitate them, we need to remove `Encoding` here.
|
||||
abstract class Encoding extends Codec<String, List<int>> {
|
||||
const Encoding();
|
||||
}
|
||||
|
||||
// TODO(floitsch): add other encodings, like ASCII and ISO_8859_1.
|
||||
@@ -4,6 +4,56 @@
|
||||
|
||||
part of dart.convert;
|
||||
|
||||
final JSON = new JsonCodec();
|
||||
|
||||
/**
|
||||
* A [JsonCodec] encodes JSON objects to strings and decodes strings to
|
||||
* JSON objects.
|
||||
*/
|
||||
class JsonCodec extends Codec<Object, String> {
|
||||
const JsonCodec();
|
||||
|
||||
/**
|
||||
* Creates a `JsonCodec` with the given reviver.
|
||||
*
|
||||
* The [reviver] function is called once for each object or list property
|
||||
* that has been parsed during decoding. The `key` argument is either the
|
||||
* integer list index for a list property, the map string for object
|
||||
* properties, or `null` for the final result.
|
||||
*/
|
||||
factory JsonCodec.withReviver(reviver(var key, var value)) =
|
||||
_ReviverJsonCodec;
|
||||
|
||||
/**
|
||||
* Parses the string and returns the resulting Json object.
|
||||
*
|
||||
* The optional [reviver] function is called once for each object or list
|
||||
* property that has been parsed during decoding. The `key` argument is either
|
||||
* the integer list index for a list property, the map string for object
|
||||
* properties, or `null` for the final result.
|
||||
*
|
||||
* The default [reviver] (when not provided) is the identity function.
|
||||
*/
|
||||
Object decode(String str, {reviver(var key, var value)}) {
|
||||
return new JsonDecoder(reviver).convert(str);
|
||||
}
|
||||
|
||||
JsonEncoder get encoder => new JsonEncoder();
|
||||
JsonDecoder get decoder => new JsonDecoder(null);
|
||||
}
|
||||
|
||||
class _ReviverJsonCodec extends JsonCodec {
|
||||
final Function _reviver;
|
||||
_ReviverJsonCodec(this._reviver);
|
||||
|
||||
Object decode(String str, {reviver(var key, var value)}) {
|
||||
if (reviver == null) reviver = _reviver;
|
||||
return new JsonDecoder(reviver).convert(str);
|
||||
}
|
||||
|
||||
JsonDecoder get decoder => new JsonDecoder(_reviver);
|
||||
}
|
||||
|
||||
/**
|
||||
* A [JsonEncoder] converts JSON objects to strings.
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,51 @@
|
||||
|
||||
part of dart.convert;
|
||||
|
||||
const UTF8 = const Utf8Codec();
|
||||
|
||||
/**
|
||||
* A [Utf8Codec] encodes strings to utf-8 code units (bytes) and decodes
|
||||
* UTF-8 code units to strings.
|
||||
*/
|
||||
class Utf8Codec extends Encoding {
|
||||
final bool _allowMalformed;
|
||||
|
||||
/**
|
||||
* Instantiates a new [Utf8Codec].
|
||||
*
|
||||
* The optional [allowMalformed] argument defines how [decoder] (and [decode])
|
||||
* deal with invalid or unterminated character sequences.
|
||||
*
|
||||
* If it is `true` (and not overriden at the method invocation) [decode] and
|
||||
* the [decoder] replace invalid (or unterminated) octet
|
||||
* sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise
|
||||
* they throw a [FormatException].
|
||||
*/
|
||||
const Utf8Codec({ bool allowMalformed: false })
|
||||
: _allowMalformed = allowMalformed;
|
||||
|
||||
/**
|
||||
* Decodes the UTF-8 [codeUnits] (a list of unsigned 8-bit integers) to the
|
||||
* corresponding string.
|
||||
*
|
||||
* If [allowMalformed] is `true` the decoder replaces invalid (or
|
||||
* unterminated) character sequences with the Unicode Replacement character
|
||||
* `U+FFFD` (�). Otherwise it throws a [FormatException].
|
||||
*
|
||||
* If [allowMalformed] is not given, it defaults to the `allowMalformed` that
|
||||
* was used to instantiate `this`.
|
||||
*/
|
||||
String decode(List<int> codeUnits, { bool allowMalformed }) {
|
||||
if (allowMalformed == null) allowMalformed = _allowMalformed;
|
||||
return new Utf8Decoder(allowMalformed: allowMalformed).convert(codeUnits);
|
||||
}
|
||||
|
||||
Converter<String, List<int>> get encoder => new Utf8Encoder();
|
||||
Converter<List<int>, String> get decoder {
|
||||
return new Utf8Decoder(allowMalformed: _allowMalformed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A [Utf8Encoder] converts strings to their UTF-8 code units (a list of
|
||||
* unsigned 8-bit integers).
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// 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:codec';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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:codec';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
library utf8_test;
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:convert';
|
||||
import 'dart:codec';
|
||||
|
||||
String decode(List<int> bytes) => new Utf8Decoder().convert(bytes);
|
||||
String decodeAllowMalformed(List<int> bytes) {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
library utf8_test;
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:codec';
|
||||
import 'dart:convert';
|
||||
|
||||
main() {
|
||||
|
||||
+2
-2
@@ -31,8 +31,8 @@
|
||||
# ......async/
|
||||
# ......collection/
|
||||
# ......_collection_dev/
|
||||
# ......convert/
|
||||
# ......core/
|
||||
# ......crypto/
|
||||
# ......html/
|
||||
# ......io/
|
||||
# ......isolate/
|
||||
@@ -198,7 +198,7 @@ def Main(argv):
|
||||
join('_internal', 'dartdoc'),
|
||||
join('_internal', 'pub', 'resource'),
|
||||
join('_internal', 'lib'),
|
||||
'async', 'collection', '_collection_dev', 'codec', 'convert',
|
||||
'async', 'collection', '_collection_dev', 'convert',
|
||||
'core', 'crypto', 'io', 'isolate',
|
||||
join('chrome', 'dart2js'), join('chrome', 'dartium'),
|
||||
join('html', 'dart2js'), join('html', 'dartium'),
|
||||
|
||||
Reference in New Issue
Block a user