pkg/utf: fixed layout, added todos, updated docs and homepage pubspec links

R=sigmund@google.com

Review URL: https://codereview.chromium.org//418433003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/utf@38534 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/lib/constants.dart b/lib/src/constants.dart
similarity index 97%
rename from lib/constants.dart
rename to lib/src/constants.dart
index 11d0cc2..3dfea39 100644
--- a/lib/constants.dart
+++ b/lib/src/constants.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.
 
-part of utf;
+library utf.constants;
 
 /**
  * Invalid codepoints or encodings may be substituted with the value U+fffd.
diff --git a/lib/list_range.dart b/lib/src/list_range.dart
similarity index 83%
rename from lib/list_range.dart
rename to lib/src/list_range.dart
index 06adb76..7889796 100644
--- a/lib/list_range.dart
+++ b/lib/src/list_range.dart
@@ -2,7 +2,9 @@
 // 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 utf;
+library utf.list_range;
+
+import 'dart:collection';
 
 /**
  * _ListRange in an internal type used to create a lightweight Interable on a
@@ -11,12 +13,12 @@
  */
 // TODO(floitsch): Consider removing the extend and switch to implements since
 // that's cheaper to allocate.
-class _ListRange extends IterableBase {
+class ListRange extends IterableBase {
   final List _source;
   final int _offset;
   final int _length;
 
-  _ListRange(source, [offset = 0, length]) :
+  ListRange(source, [offset = 0, length]) :
       this._source = source,
       this._offset = offset,
       this._length = (length == null ? source.length - offset : length) {
@@ -31,18 +33,18 @@
     }
   }
 
-  _ListRangeIterator get iterator =>
+  ListRangeIterator get iterator =>
       new _ListRangeIteratorImpl(_source, _offset, _offset + _length);
 
   int get length => _length;
 }
 
 /**
- * The _ListRangeIterator provides more capabilities than a standard iterator,
+ * The ListRangeIterator provides more capabilities than a standard iterator,
  * including the ability to get the current position, count remaining items,
  * and move forward/backward within the iterator.
  */
-abstract class _ListRangeIterator implements Iterator<int> {
+abstract class ListRangeIterator implements Iterator<int> {
   bool moveNext();
   int get current;
   int get position;
@@ -51,7 +53,7 @@
   void skip([count]);
 }
 
-class _ListRangeIteratorImpl implements _ListRangeIterator {
+class _ListRangeIteratorImpl implements ListRangeIterator {
   final List<int> _source;
   int _offset;
   final int _end;
@@ -75,4 +77,3 @@
     _offset += count;
   }
 }
-
diff --git a/lib/utf16.dart b/lib/src/utf/utf16.dart
similarity index 69%
rename from lib/utf16.dart
rename to lib/src/utf/utf16.dart
index 438c678..8ddd4dd 100644
--- a/lib/utf16.dart
+++ b/lib/src/utf/utf16.dart
@@ -11,7 +11,7 @@
 List<int> stringToCodepoints(String str) {
   // Note: str.codeUnits gives us 16-bit code units on all Dart implementations.
   // So we need to convert.
-  return _utf16CodeUnitsToCodepoints(str.codeUnits);
+  return utf16CodeUnitsToCodepoints(str.codeUnits);
 }
 
 /**
@@ -19,152 +19,10 @@
  *
  * *Deprecated* Use [String.fromCharCodes] instead.
  */
+@deprecated
 String codepointsToString(List<int> codepoints) {
   return new String.fromCharCodes(codepoints);
 }
-
-/**
- * An Iterator<int> of codepoints built on an Iterator of UTF-16 code units.
- * The parameters can override the default Unicode replacement character. Set
- * the replacementCharacter to null to throw an ArgumentError
- * rather than replace the bad value.
- */
-class Utf16CodeUnitDecoder implements Iterator<int> {
-  final _ListRangeIterator utf16CodeUnitIterator;
-  final int replacementCodepoint;
-  int _current = null;
-
-  Utf16CodeUnitDecoder(List<int> utf16CodeUnits, [int offset = 0, int length,
-      int this.replacementCodepoint =
-      UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
-      utf16CodeUnitIterator =
-          (new _ListRange(utf16CodeUnits, offset, length)).iterator;
-
-  Utf16CodeUnitDecoder.fromListRangeIterator(
-      _ListRangeIterator this.utf16CodeUnitIterator,
-      int this.replacementCodepoint);
-
-  Iterator<int> get iterator => this;
-
-  int get current => _current;
-
-  bool moveNext() {
-    _current = null;
-    if (!utf16CodeUnitIterator.moveNext()) return false;
-
-    int value = utf16CodeUnitIterator.current;
-    if (value < 0) {
-      if (replacementCodepoint != null) {
-        _current = replacementCodepoint;
-      } else {
-        throw new ArgumentError(
-            "Invalid UTF16 at ${utf16CodeUnitIterator.position}");
-      }
-    } else if (value < UNICODE_UTF16_RESERVED_LO ||
-        (value > UNICODE_UTF16_RESERVED_HI && value <= UNICODE_PLANE_ONE_MAX)) {
-      // transfer directly
-      _current = value;
-    } else if (value < UNICODE_UTF16_SURROGATE_UNIT_1_BASE &&
-        utf16CodeUnitIterator.moveNext()) {
-      // merge surrogate pair
-      int nextValue = utf16CodeUnitIterator.current;
-      if (nextValue >= UNICODE_UTF16_SURROGATE_UNIT_1_BASE &&
-          nextValue <= UNICODE_UTF16_RESERVED_HI) {
-        value = (value - UNICODE_UTF16_SURROGATE_UNIT_0_BASE) << 10;
-        value += UNICODE_UTF16_OFFSET +
-            (nextValue - UNICODE_UTF16_SURROGATE_UNIT_1_BASE);
-        _current = value;
-      } else {
-        if (nextValue >= UNICODE_UTF16_SURROGATE_UNIT_0_BASE &&
-           nextValue < UNICODE_UTF16_SURROGATE_UNIT_1_BASE) {
-          utf16CodeUnitIterator.backup();
-        }
-        if (replacementCodepoint != null) {
-          _current = replacementCodepoint;
-        } else {
-          throw new ArgumentError(
-              "Invalid UTF16 at ${utf16CodeUnitIterator.position}");
-        }
-      }
-    } else if (replacementCodepoint != null) {
-      _current = replacementCodepoint;
-    } else {
-      throw new ArgumentError(
-          "Invalid UTF16 at ${utf16CodeUnitIterator.position}");
-    }
-    return true;
-  }
-}
-
-/**
- * Encode code points as UTF16 code units.
- */
-List<int> _codepointsToUtf16CodeUnits(
-    List<int> codepoints,
-    [int offset = 0,
-     int length,
-     int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
-
-  _ListRange listRange = new _ListRange(codepoints, offset, length);
-  int encodedLength = 0;
-  for (int value in listRange) {
-    if ((value >= 0 && value < UNICODE_UTF16_RESERVED_LO) ||
-        (value > UNICODE_UTF16_RESERVED_HI && value <= UNICODE_PLANE_ONE_MAX)) {
-      encodedLength++;
-    } else if (value > UNICODE_PLANE_ONE_MAX &&
-        value <= UNICODE_VALID_RANGE_MAX) {
-      encodedLength += 2;
-    } else {
-      encodedLength++;
-    }
-  }
-
-  List<int> codeUnitsBuffer = new List<int>(encodedLength);
-  int j = 0;
-  for (int value in listRange) {
-    if ((value >= 0 && value < UNICODE_UTF16_RESERVED_LO) ||
-        (value > UNICODE_UTF16_RESERVED_HI && value <= UNICODE_PLANE_ONE_MAX)) {
-      codeUnitsBuffer[j++] = value;
-    } else if (value > UNICODE_PLANE_ONE_MAX &&
-        value <= UNICODE_VALID_RANGE_MAX) {
-      int base = value - UNICODE_UTF16_OFFSET;
-      codeUnitsBuffer[j++] = UNICODE_UTF16_SURROGATE_UNIT_0_BASE +
-          ((base & UNICODE_UTF16_HI_MASK) >> 10);
-      codeUnitsBuffer[j++] = UNICODE_UTF16_SURROGATE_UNIT_1_BASE +
-          (base & UNICODE_UTF16_LO_MASK);
-    } else if (replacementCodepoint != null) {
-      codeUnitsBuffer[j++] = replacementCodepoint;
-    } else {
-      throw new ArgumentError("Invalid encoding");
-    }
-  }
-  return codeUnitsBuffer;
-}
-
-/**
- * Decodes the utf16 codeunits to codepoints.
- */
-List<int> _utf16CodeUnitsToCodepoints(
-    List<int> utf16CodeUnits, [int offset = 0, int length,
-    int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
-  _ListRangeIterator source =
-      (new _ListRange(utf16CodeUnits, offset, length)).iterator;
-  Utf16CodeUnitDecoder decoder = new Utf16CodeUnitDecoder
-      .fromListRangeIterator(source, replacementCodepoint);
-  List<int> codepoints = new List<int>(source.remaining);
-  int i = 0;
-  while (decoder.moveNext()) {
-    codepoints[i++] = decoder.current;
-  }
-  if (i == codepoints.length) {
-    return codepoints;
-  } else {
-    List<int> codepointTrunc = new List<int>(i);
-    codepointTrunc.setRange(0, i, codepoints);
-    return codepointTrunc;
-  }
-}
-
 /**
  * Decodes the UTF-16 bytes as an iterable. Thus, the consumer can only convert
  * as much of the input as needed. Determines the byte order from the BOM,
@@ -225,7 +83,7 @@
       offset, length, replacementCodepoint);
   List<int> codeunits = decoder.decodeRest();
   return new String.fromCharCodes(
-      _utf16CodeUnitsToCodepoints(codeunits, 0, null, replacementCodepoint));
+      utf16CodeUnitsToCodepoints(codeunits, 0, null, replacementCodepoint));
 }
 
 /**
@@ -241,7 +99,7 @@
   List<int> codeunits = (new Utf16beBytesToCodeUnitsDecoder(bytes, offset,
       length, stripBom, replacementCodepoint)).decodeRest();
   return new String.fromCharCodes(
-      _utf16CodeUnitsToCodepoints(codeunits, 0, null, replacementCodepoint));
+      utf16CodeUnitsToCodepoints(codeunits, 0, null, replacementCodepoint));
 }
 
 /**
@@ -257,7 +115,7 @@
   List<int> codeunits = (new Utf16leBytesToCodeUnitsDecoder(bytes, offset,
       length, stripBom, replacementCodepoint)).decodeRest();
   return new String.fromCharCodes(
-      _utf16CodeUnitsToCodepoints(codeunits, 0, null, replacementCodepoint));
+      utf16CodeUnitsToCodepoints(codeunits, 0, null, replacementCodepoint));
 }
 
 /**
@@ -339,10 +197,10 @@
 }
 
 List<int> _stringToUtf16CodeUnits(String str) {
-  return _codepointsToUtf16CodeUnits(str.codeUnits);
+  return codepointsToUtf16CodeUnits(str.codeUnits);
 }
 
-typedef _ListRangeIterator _CodeUnitsProvider();
+typedef ListRangeIterator _CodeUnitsProvider();
 
 /**
  * Return type of [decodeUtf16AsIterable] and variants. The Iterable type
@@ -367,8 +225,9 @@
  * to produce the code unit (0-(2^16)-1). Relies on BOM to determine
  * endian-ness, and defaults to BE.
  */
-abstract class Utf16BytesToCodeUnitsDecoder implements _ListRangeIterator {
-  final _ListRangeIterator utf16EncodedBytesIterator;
+abstract class Utf16BytesToCodeUnitsDecoder implements ListRangeIterator {
+  // TODO(kevmoo): should this field be private?
+  final ListRangeIterator utf16EncodedBytesIterator;
   final int replacementCodepoint;
   int _current = null;
 
@@ -460,7 +319,7 @@
       int offset = 0, int length, bool stripBom = true,
       int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
       super._fromListRangeIterator(
-          (new _ListRange(utf16EncodedBytes, offset, length)).iterator,
+          (new ListRange(utf16EncodedBytes, offset, length)).iterator,
           replacementCodepoint) {
     if (stripBom && hasUtf16beBom(utf16EncodedBytes, offset, length)) {
       skip();
@@ -485,7 +344,7 @@
       int offset = 0, int length, bool stripBom = true,
       int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
       super._fromListRangeIterator(
-          (new _ListRange(utf16EncodedBytes, offset, length)).iterator,
+          (new ListRange(utf16EncodedBytes, offset, length)).iterator,
           replacementCodepoint) {
     if (stripBom && hasUtf16leBom(utf16EncodedBytes, offset, length)) {
       skip();
diff --git a/lib/utf32.dart b/lib/src/utf/utf32.dart
similarity index 97%
rename from lib/utf32.dart
rename to lib/src/utf/utf32.dart
index c481c81..e51009d 100644
--- a/lib/utf32.dart
+++ b/lib/src/utf/utf32.dart
@@ -195,8 +195,9 @@
 /**
  * Abstrace parent class converts encoded bytes to codepoints.
  */
-abstract class Utf32BytesDecoder implements _ListRangeIterator {
-  final _ListRangeIterator utf32EncodedBytesIterator;
+abstract class Utf32BytesDecoder implements ListRangeIterator {
+  // TODO(kevmoo): should this field be private?
+  final ListRangeIterator utf32EncodedBytesIterator;
   final int replacementCodepoint;
   int _current = null;
 
@@ -286,7 +287,7 @@
       int length, bool stripBom = true,
       int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
       super._fromListRangeIterator(
-          (new _ListRange(utf32EncodedBytes, offset, length)).iterator,
+          (new ListRange(utf32EncodedBytes, offset, length)).iterator,
           replacementCodepoint) {
     if (stripBom && hasUtf32beBom(utf32EncodedBytes, offset, length)) {
       skip();
@@ -315,7 +316,7 @@
       int length, bool stripBom = true,
       int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
       super._fromListRangeIterator(
-          (new _ListRange(utf32EncodedBytes, offset, length)).iterator,
+          (new ListRange(utf32EncodedBytes, offset, length)).iterator,
           replacementCodepoint) {
     if (stripBom && hasUtf32leBom(utf32EncodedBytes, offset, length)) {
       skip();
diff --git a/lib/utf8.dart b/lib/src/utf/utf8.dart
similarity index 96%
rename from lib/utf8.dart
rename to lib/src/utf/utf8.dart
index 36288d9..ff1b1ed 100644
--- a/lib/utf8.dart
+++ b/lib/src/utf/utf8.dart
@@ -69,7 +69,7 @@
  */
 List<int> codepointsToUtf8(
     List<int> codepoints, [int offset = 0, int length]) {
-  _ListRange source = new _ListRange(codepoints, offset, length);
+  ListRange source = new ListRange(codepoints, offset, length);
 
   int encodedLength = 0;
   for (int value in source) {
@@ -153,7 +153,8 @@
  * from this method can be used as an Iterable (e.g. in a for-loop).
  */
 class Utf8Decoder implements Iterator<int> {
-  final _ListRangeIterator utf8EncodedBytesIterator;
+  // TODO(kevmoo): should this field be private?
+  final ListRangeIterator utf8EncodedBytesIterator;
   final int replacementCodepoint;
   int _current = null;
 
@@ -161,10 +162,10 @@
       this.replacementCodepoint =
       UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
       utf8EncodedBytesIterator =
-          (new _ListRange(utf8EncodedBytes, offset, length)).iterator;
+          (new ListRange(utf8EncodedBytes, offset, length)).iterator;
 
 
-  Utf8Decoder._fromListRangeIterator(_ListRange source, [
+  Utf8Decoder._fromListRangeIterator(ListRange source, [
       this.replacementCodepoint =
       UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
       utf8EncodedBytesIterator = source.iterator;
diff --git a/lib/utf_stream.dart b/lib/src/utf/utf_stream.dart
similarity index 98%
rename from lib/utf_stream.dart
rename to lib/src/utf/utf_stream.dart
index bb36dca..2b460d0 100644
--- a/lib/utf_stream.dart
+++ b/lib/src/utf/utf_stream.dart
@@ -205,7 +205,7 @@
   List<int> _processString(String string) {
     var bytes = [];
     int pos = 0;
-    List<int> codepoints = _utf16CodeUnitsToCodepoints(string.codeUnits);
+    List<int> codepoints = utf16CodeUnitsToCodepoints(string.codeUnits);
     int length = codepoints.length;
     for (int i = 0; i < length; i++) {
       int additionalBytes;
diff --git a/lib/src/utf_16_code_unit_decoder.dart b/lib/src/utf_16_code_unit_decoder.dart
new file mode 100644
index 0000000..a0a4b3c
--- /dev/null
+++ b/lib/src/utf_16_code_unit_decoder.dart
@@ -0,0 +1,83 @@
+// Copyright (c) 2012, 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.
+
+library utf.utf_16_code_unit_decoder;
+
+import 'constants.dart';
+import 'list_range.dart';
+
+/**
+ * An Iterator<int> of codepoints built on an Iterator of UTF-16 code units.
+ * The parameters can override the default Unicode replacement character. Set
+ * the replacementCharacter to null to throw an ArgumentError
+ * rather than replace the bad value.
+ */
+class Utf16CodeUnitDecoder implements Iterator<int> {
+  // TODO(kevmoo): should this field be private?
+  final ListRangeIterator utf16CodeUnitIterator;
+  final int replacementCodepoint;
+  int _current = null;
+
+  Utf16CodeUnitDecoder(List<int> utf16CodeUnits, [int offset = 0, int length,
+      int this.replacementCodepoint =
+      UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) :
+      utf16CodeUnitIterator =
+          (new ListRange(utf16CodeUnits, offset, length)).iterator;
+
+  Utf16CodeUnitDecoder.fromListRangeIterator(
+      ListRangeIterator this.utf16CodeUnitIterator,
+      int this.replacementCodepoint);
+
+  Iterator<int> get iterator => this;
+
+  int get current => _current;
+
+  bool moveNext() {
+    _current = null;
+    if (!utf16CodeUnitIterator.moveNext()) return false;
+
+    int value = utf16CodeUnitIterator.current;
+    if (value < 0) {
+      if (replacementCodepoint != null) {
+        _current = replacementCodepoint;
+      } else {
+        throw new ArgumentError(
+            "Invalid UTF16 at ${utf16CodeUnitIterator.position}");
+      }
+    } else if (value < UNICODE_UTF16_RESERVED_LO ||
+        (value > UNICODE_UTF16_RESERVED_HI && value <= UNICODE_PLANE_ONE_MAX)) {
+      // transfer directly
+      _current = value;
+    } else if (value < UNICODE_UTF16_SURROGATE_UNIT_1_BASE &&
+        utf16CodeUnitIterator.moveNext()) {
+      // merge surrogate pair
+      int nextValue = utf16CodeUnitIterator.current;
+      if (nextValue >= UNICODE_UTF16_SURROGATE_UNIT_1_BASE &&
+          nextValue <= UNICODE_UTF16_RESERVED_HI) {
+        value = (value - UNICODE_UTF16_SURROGATE_UNIT_0_BASE) << 10;
+        value += UNICODE_UTF16_OFFSET +
+            (nextValue - UNICODE_UTF16_SURROGATE_UNIT_1_BASE);
+        _current = value;
+      } else {
+        if (nextValue >= UNICODE_UTF16_SURROGATE_UNIT_0_BASE &&
+           nextValue < UNICODE_UTF16_SURROGATE_UNIT_1_BASE) {
+          utf16CodeUnitIterator.backup();
+        }
+        if (replacementCodepoint != null) {
+          _current = replacementCodepoint;
+        } else {
+          throw new ArgumentError(
+              "Invalid UTF16 at ${utf16CodeUnitIterator.position}");
+        }
+      }
+    } else if (replacementCodepoint != null) {
+      _current = replacementCodepoint;
+    } else {
+      throw new ArgumentError(
+          "Invalid UTF16 at ${utf16CodeUnitIterator.position}");
+    }
+    return true;
+  }
+}
+
diff --git a/lib/src/util.dart b/lib/src/util.dart
new file mode 100644
index 0000000..17427d5
--- /dev/null
+++ b/lib/src/util.dart
@@ -0,0 +1,78 @@
+// Copyright (c) 2012, 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.
+
+library utf.util;
+
+import 'constants.dart';
+import 'list_range.dart';
+import 'utf_16_code_unit_decoder.dart';
+
+/**
+ * Decodes the utf16 codeunits to codepoints.
+ */
+List<int> utf16CodeUnitsToCodepoints(
+    List<int> utf16CodeUnits, [int offset = 0, int length,
+    int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
+  ListRangeIterator source =
+      (new ListRange(utf16CodeUnits, offset, length)).iterator;
+  Utf16CodeUnitDecoder decoder = new Utf16CodeUnitDecoder
+      .fromListRangeIterator(source, replacementCodepoint);
+  List<int> codepoints = new List<int>(source.remaining);
+  int i = 0;
+  while (decoder.moveNext()) {
+    codepoints[i++] = decoder.current;
+  }
+  if (i == codepoints.length) {
+    return codepoints;
+  } else {
+    List<int> codepointTrunc = new List<int>(i);
+    codepointTrunc.setRange(0, i, codepoints);
+    return codepointTrunc;
+  }
+}
+
+/**
+ * Encode code points as UTF16 code units.
+ */
+List<int> codepointsToUtf16CodeUnits(
+    List<int> codepoints,
+    [int offset = 0,
+     int length,
+     int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
+
+  ListRange listRange = new ListRange(codepoints, offset, length);
+  int encodedLength = 0;
+  for (int value in listRange) {
+    if ((value >= 0 && value < UNICODE_UTF16_RESERVED_LO) ||
+        (value > UNICODE_UTF16_RESERVED_HI && value <= UNICODE_PLANE_ONE_MAX)) {
+      encodedLength++;
+    } else if (value > UNICODE_PLANE_ONE_MAX &&
+        value <= UNICODE_VALID_RANGE_MAX) {
+      encodedLength += 2;
+    } else {
+      encodedLength++;
+    }
+  }
+
+  List<int> codeUnitsBuffer = new List<int>(encodedLength);
+  int j = 0;
+  for (int value in listRange) {
+    if ((value >= 0 && value < UNICODE_UTF16_RESERVED_LO) ||
+        (value > UNICODE_UTF16_RESERVED_HI && value <= UNICODE_PLANE_ONE_MAX)) {
+      codeUnitsBuffer[j++] = value;
+    } else if (value > UNICODE_PLANE_ONE_MAX &&
+        value <= UNICODE_VALID_RANGE_MAX) {
+      int base = value - UNICODE_UTF16_OFFSET;
+      codeUnitsBuffer[j++] = UNICODE_UTF16_SURROGATE_UNIT_0_BASE +
+          ((base & UNICODE_UTF16_HI_MASK) >> 10);
+      codeUnitsBuffer[j++] = UNICODE_UTF16_SURROGATE_UNIT_1_BASE +
+          (base & UNICODE_UTF16_LO_MASK);
+    } else if (replacementCodepoint != null) {
+      codeUnitsBuffer[j++] = replacementCodepoint;
+    } else {
+      throw new ArgumentError("Invalid encoding");
+    }
+  }
+  return codeUnitsBuffer;
+}
diff --git a/lib/utf.dart b/lib/utf.dart
index 1028990..30d5db5 100644
--- a/lib/utf.dart
+++ b/lib/utf.dart
@@ -11,9 +11,15 @@
 import "dart:async";
 import "dart:collection";
 
-part "constants.dart";
-part "list_range.dart";
-part "utf_stream.dart";
-part "utf8.dart";
-part "utf16.dart";
-part "utf32.dart";
+import "src/constants.dart";
+import 'src/utf_16_code_unit_decoder.dart';
+import 'src/list_range.dart';
+import 'src/util.dart';
+
+export 'src/constants.dart';
+export 'src/utf_16_code_unit_decoder.dart';
+
+part "src/utf/utf_stream.dart";
+part "src/utf/utf8.dart";
+part "src/utf/utf16.dart";
+part "src/utf/utf32.dart";
diff --git a/pubspec.yaml b/pubspec.yaml
index e997dac..a3fd334 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,12 +1,9 @@
 name: utf
-version: 0.9.0
+version: 0.9.0+1
 author: Dart Team <misc@dartlang.org>
 description: >
  A Unicode library. Intended for advanced use where the built-in facilities
  are too limiting.
-homepage: http://www.dartlang.org
-documentation: http://api.dartlang.org/docs/pkg/utf
-dev_dependencies:
-  unittest: ">=0.9.0 <0.10.0"
+homepage: https://pub.dartlang.org/packages/utf
 environment:
-  sdk: ">=0.8.10+6 <2.0.0"
+  sdk: '>=1.0.0 <2.0.0'
diff --git a/test/unicode_core_test.dart b/test/unicode_core_test.dart
index 129273b..6e13e96 100755
--- a/test/unicode_core_test.dart
+++ b/test/unicode_core_test.dart
@@ -2,91 +2,90 @@
 // 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 utf;
+library utf.unicode_core_test;
+
 import 'package:expect/expect.dart';
-import 'dart:collection';
 
-part '../lib/constants.dart';
-part '../lib/list_range.dart';
-part '../lib/utf16.dart';
+import 'package:utf/utf.dart';
+import 'package:utf/src/util.dart';
 
-main() {
+void main() {
   testCodepointsToUtf16CodeUnits();
   testUtf16bytesToCodepoints();
 }
 
 void testCodepointsToUtf16CodeUnits() {
   // boundary conditions
-  Expect.listEquals([], _codepointsToUtf16CodeUnits([]), "no input");
-  Expect.listEquals([0x0], _codepointsToUtf16CodeUnits([0x0]), "0");
+  Expect.listEquals([], codepointsToUtf16CodeUnits([]), "no input");
+  Expect.listEquals([0x0], codepointsToUtf16CodeUnits([0x0]), "0");
   Expect.listEquals([0xd800, 0xdc00],
-      _codepointsToUtf16CodeUnits([0x10000]), "10000");
+      codepointsToUtf16CodeUnits([0x10000]), "10000");
 
   Expect.listEquals([0xffff],
-      _codepointsToUtf16CodeUnits([0xffff]), "ffff");
+      codepointsToUtf16CodeUnits([0xffff]), "ffff");
   Expect.listEquals([0xdbff, 0xdfff],
-      _codepointsToUtf16CodeUnits([0x10ffff]), "10ffff");
+      codepointsToUtf16CodeUnits([0x10ffff]), "10ffff");
 
   Expect.listEquals([0xd7ff],
-      _codepointsToUtf16CodeUnits([0xd7ff]), "d7ff");
+      codepointsToUtf16CodeUnits([0xd7ff]), "d7ff");
   Expect.listEquals([0xe000],
-      _codepointsToUtf16CodeUnits([0xe000]), "e000");
+      codepointsToUtf16CodeUnits([0xe000]), "e000");
 
   Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
-      _codepointsToUtf16CodeUnits([0xd800]), "d800");
+      codepointsToUtf16CodeUnits([0xd800]), "d800");
   Expect.listEquals([UNICODE_REPLACEMENT_CHARACTER_CODEPOINT],
-      _codepointsToUtf16CodeUnits([0xdfff]), "dfff");
+      codepointsToUtf16CodeUnits([0xdfff]), "dfff");
 }
 
 void testUtf16bytesToCodepoints() {
   // boundary conditions: First possible values
-  Expect.listEquals([], _utf16CodeUnitsToCodepoints([]), "no input");
-  Expect.listEquals([0x0], _utf16CodeUnitsToCodepoints([0x0]), "0");
+  Expect.listEquals([], utf16CodeUnitsToCodepoints([]), "no input");
+  Expect.listEquals([0x0], utf16CodeUnitsToCodepoints([0x0]), "0");
   Expect.listEquals([0x10000],
-      _utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000");
+      utf16CodeUnitsToCodepoints([0xd800, 0xdc00]), "10000");
 
   // boundary conditions: Last possible sequence of a certain length
   Expect.listEquals([0xffff],
-      _utf16CodeUnitsToCodepoints([0xffff]), "ffff");
+      utf16CodeUnitsToCodepoints([0xffff]), "ffff");
   Expect.listEquals([0x10ffff],
-      _utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff");
+      utf16CodeUnitsToCodepoints([0xdbff, 0xdfff]), "10ffff");
 
   // other boundary conditions
   Expect.listEquals([0xd7ff],
-      _utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff");
+      utf16CodeUnitsToCodepoints([0xd7ff]), "d7ff");
   Expect.listEquals([0xe000],
-      _utf16CodeUnitsToCodepoints([0xe000]), "e000");
+      utf16CodeUnitsToCodepoints([0xe000]), "e000");
 
   // unexpected continuation bytes
   Expect.listEquals([0xfffd],
-      _utf16CodeUnitsToCodepoints([0xdc00]),
+      utf16CodeUnitsToCodepoints([0xdc00]),
       "dc00 first unexpected continuation byte");
   Expect.listEquals([0xfffd],
-      _utf16CodeUnitsToCodepoints([0xdfff]),
+      utf16CodeUnitsToCodepoints([0xdfff]),
       "dfff last unexpected continuation byte");
   Expect.listEquals([0xfffd],
-      _utf16CodeUnitsToCodepoints([0xdc00]),
+      utf16CodeUnitsToCodepoints([0xdc00]),
       "1 unexpected continuation bytes");
   Expect.listEquals([0xfffd, 0xfffd],
-      _utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]),
+      utf16CodeUnitsToCodepoints([0xdc00, 0xdc00]),
       "2 unexpected continuation bytes");
   Expect.listEquals([0xfffd, 0xfffd ,0xfffd],
-      _utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]),
+      utf16CodeUnitsToCodepoints([0xdc00, 0xdc00, 0xdc00]),
       "3 unexpected continuation bytes");
 
   // incomplete sequences
-  Expect.listEquals([0xfffd], _utf16CodeUnitsToCodepoints([0xd800]),
+  Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xd800]),
       "d800 last byte missing");
-  Expect.listEquals([0xfffd], _utf16CodeUnitsToCodepoints([0xdbff]),
+  Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0xdbff]),
       "dbff last byte missing");
 
   // concatenation of incomplete sequences
   Expect.listEquals([0xfffd, 0xfffd],
-      _utf16CodeUnitsToCodepoints([0xd800, 0xdbff]),
+      utf16CodeUnitsToCodepoints([0xd800, 0xdbff]),
       "d800 dbff last byte missing");
 
   // impossible bytes
-  Expect.listEquals([0xfffd], _utf16CodeUnitsToCodepoints([0x110000]),
+  Expect.listEquals([0xfffd], utf16CodeUnitsToCodepoints([0x110000]),
       "110000 out of bounds");
 
   // overlong sequences not possible in utf16 (nothing < x10000)
diff --git a/test/utf16_test.dart b/test/utf16_test.dart
index 6af766f..43971ca 100755
--- a/test/utf16_test.dart
+++ b/test/utf16_test.dart
@@ -2,7 +2,8 @@
 // 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 utf16_tests;
+library utf.utf16_test;
+
 import 'package:expect/expect.dart';
 import 'package:utf/utf.dart';
 
diff --git a/test/utf32_test.dart b/test/utf32_test.dart
index 4fcdf29..1a60a6f 100755
--- a/test/utf32_test.dart
+++ b/test/utf32_test.dart
@@ -2,6 +2,8 @@
 // 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 utf.utf32_test;
+
 import 'package:expect/expect.dart';
 import 'package:utf/utf.dart';
 
diff --git a/test/utf82_test.dart b/test/utf82_test.dart
index f8d585c..7f8cec4 100755
--- a/test/utf82_test.dart
+++ b/test/utf82_test.dart
@@ -2,6 +2,8 @@
 // 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 utf.utf82_test;
+
 import 'package:expect/expect.dart';
 import 'package:utf/utf.dart';
 
diff --git a/test/utf8_test.dart b/test/utf8_test.dart
index af46557..3e8c87e 100644
--- a/test/utf8_test.dart
+++ b/test/utf8_test.dart
@@ -2,7 +2,8 @@
 // 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 utf8_test;
+library utf.utf8_test;
+
 import "package:expect/expect.dart";
 import "package:utf/utf.dart";
 
diff --git a/test/utf_test.dart b/test/utf_test.dart
index c4a1e94..86d08e4 100644
--- a/test/utf_test.dart
+++ b/test/utf_test.dart
@@ -2,7 +2,8 @@
 // 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 utf_test;
+library utf.utf_test;
+
 import "package:expect/expect.dart";
 import "package:utf/utf.dart";