Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Unified Diff: sdk/lib/convert/utf.dart

Issue 25463003: Fix UTF8 encoder for Unicode runes > 0xFFFF. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/convert/unicode_tests.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/convert/utf.dart
diff --git a/sdk/lib/convert/utf.dart b/sdk/lib/convert/utf.dart
index 6abaa0519b959200fe49ec33d7df190bd23fc352..b350f7d5efab7583a474f7a7da2858b8741a2736 100644
--- a/sdk/lib/convert/utf.dart
+++ b/sdk/lib/convert/utf.dart
@@ -7,6 +7,9 @@ part of dart.convert;
/** The Unicode Replacement character `U+FFFD` (�). */
const UNICODE_REPLACEMENT_CHARACTER_RUNE = 0xFFFD;
+/** The Unicode Byte Order Marker (BOM) character `U+FEFF`. */
+const UNICODE_BOM_CHARACTER_RUNE = 0xFEFF;
+
/**
* An instance of the default implementation of the [Utf8Codec].
*
@@ -48,6 +51,9 @@ class Utf8Codec extends Encoding {
* Decodes the UTF-8 [codeUnits] (a list of unsigned 8-bit integers) to the
* corresponding string.
*
+ * If the [codeUnits] start with a leading [UNICODE_BOM_CHARACTER_RUNE] this
Anders Johnsen 2013/10/01 11:32:29 Is this really happening? I don't see any usage of
floitsch 2013/10/01 11:37:42 There was a private copy of it. I removed that one
+ * character is discarded.
+ *
* If [allowMalformed] is `true` the decoder replaces invalid (or
* unterminated) character sequences with the Unicode Replacement character
* `U+FFFD` (�). Otherwise it throws a [FormatException].
@@ -303,6 +309,9 @@ class Utf8Decoder extends Converter<List<int>, String> {
/**
* Converts the UTF-8 [codeUnits] (a list of unsigned 8-bit integers) to the
* corresponding string.
+ *
+ * If the [codeUnits] start with a leading [UNICODE_BOM_CHARACTER_RUNE] this
+ * character is discarded.
*/
String convert(List<int> codeUnits) {
StringBuffer buffer = new StringBuffer();
@@ -356,7 +365,7 @@ bool _isLeadSurrogate(int codeUnit) =>
bool _isTailSurrogate(int codeUnit) =>
(codeUnit & _SURROGATE_TAG_MASK) == _TAIL_SURROGATE_MIN;
int _combineSurrogatePair(int lead, int tail) =>
- 0x10000 | ((lead & _SURROGATE_VALUE_MASK) << 10)
+ 0x10000 + ((lead & _SURROGATE_VALUE_MASK) << 10)
| (tail & _SURROGATE_VALUE_MASK);
« no previous file with comments | « no previous file | tests/lib/convert/unicode_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698