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

Side by Side Diff: runtime/lib/convert_patch.dart

Issue 677423002: Fix assertion not holding (calling with start==end) and typo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/convert/json_utf8_chunk_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:_internal" show POWERS_OF_TEN; 5 import "dart:_internal" show POWERS_OF_TEN;
6 6
7 // JSON conversion. 7 // JSON conversion.
8 8
9 patch _parseJson(String json, reviver(var key, var value)) { 9 patch _parseJson(String json, reviver(var key, var value)) {
10 _BuildJsonListener listener; 10 _BuildJsonListener listener;
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 int start = position; 938 int start = position;
939 int end = chunkEnd; 939 int end = chunkEnd;
940 while (position < end) { 940 while (position < end) {
941 int char = getChar(position++); 941 int char = getChar(position++);
942 // BACKSLASH is larger than QUOTE and SPACE. 942 // BACKSLASH is larger than QUOTE and SPACE.
943 if (char > BACKSLASH) { 943 if (char > BACKSLASH) {
944 continue; 944 continue;
945 } 945 }
946 if (char == BACKSLASH) { 946 if (char == BACKSLASH) {
947 beginString(); 947 beginString();
948 addSliceToString(start, position - 1); 948 int sliceEnd = position - 1;
949 if (start < sliceEnd) addSliceToString(start, sliceEnd);
949 return parseStringToBuffer(position - 1); 950 return parseStringToBuffer(position - 1);
950 } 951 }
951 if (char == QUOTE) { 952 if (char == QUOTE) {
952 listener.handleString(getString(start, position - 1)); 953 listener.handleString(getString(start, position - 1));
953 return position; 954 return position;
954 } 955 }
955 if (char < SPACE) { 956 if (char < SPACE) {
956 fail(position - 1, "Control character in string"); 957 fail(position - 1, "Control character in string");
957 } 958 }
958 } 959 }
959 beginString(); 960 beginString();
960 addSliceToString(start, end); 961 if (start < end) addSliceToString(start, end);
961 return chunkString(STR_PLAIN); 962 return chunkString(STR_PLAIN);
962 } 963 }
963 964
964 /** 965 /**
965 * Sets up a partial string state. 966 * Sets up a partial string state.
966 * 967 *
967 * The state is either not inside an escape, or right after a backslash. 968 * The state is either not inside an escape, or right after a backslash.
968 * For partial strings ending inside a Unicode escape, use 969 * For partial strings ending inside a Unicode escape, use
969 * [chunkStringEscapeU]. 970 * [chunkStringEscapeU].
970 */ 971 */
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 List<int> chunk; 1629 List<int> chunk;
1629 int chunkEnd; 1630 int chunkEnd;
1630 1631
1631 _JsonUtf8Parser(_JsonListener listener, this.allowMalformed) 1632 _JsonUtf8Parser(_JsonListener listener, this.allowMalformed)
1632 : super(listener); 1633 : super(listener);
1633 1634
1634 int getChar(int position) => chunk[position]; 1635 int getChar(int position) => chunk[position];
1635 1636
1636 String getString(int start, int end) { 1637 String getString(int start, int end) {
1637 beginString(); 1638 beginString();
1638 addSliceToString(start, end); 1639 if (start < end) addSliceToString(start, end);
1639 String result = endString(); 1640 String result = endString();
1640 return result; 1641 return result;
1641 } 1642 }
1642 1643
1643 void beginString() { 1644 void beginString() {
1644 this.buffer = new _Utf8StringBuffer(allowMalformed); 1645 this.buffer = new _Utf8StringBuffer(allowMalformed);
1645 } 1646 }
1646 1647
1647 void addSliceToString(int start, int end) { 1648 void addSliceToString(int start, int end) {
1648 _Utf8StringBuffer buffer = this.buffer; 1649 _Utf8StringBuffer buffer = this.buffer;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 _parser.parse(start); 1711 _parser.parse(start);
1711 } 1712 }
1712 1713
1713 void close() { 1714 void close() {
1714 _parser.close(); 1715 _parser.close();
1715 var decoded = _parser.result; 1716 var decoded = _parser.result;
1716 _sink.add(decoded); 1717 _sink.add(decoded);
1717 _sink.close(); 1718 _sink.close();
1718 } 1719 }
1719 } 1720 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/convert/json_utf8_chunk_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698