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

Unified Diff: lib/json/json.dart

Issue 10383164: Debugger wire protocol: setting breakpoints (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 | runtime/bin/dbg_connection.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/json/json.dart
===================================================================
--- lib/json/json.dart (revision 7627)
+++ lib/json/json.dart (working copy)
@@ -18,6 +18,15 @@
}
/**
+ * Checks validity of JSON source in [:str:] and returns its text
+ * length. Returns 0 if [:str:] does not begin with a valid JSON
+ * object.
+ */
+ static int length(String str) {
+ return _JsonParser.objectLength(str);
+ }
+
+ /**
* Serializes [:object:] into JSON string.
*/
static String stringify(Object object) {
@@ -96,6 +105,17 @@
return new _JsonParser._internal(json)._parseToplevel();
}
+ static objectLength(String str) {
+ var p = new _JsonParser._internal(str);
+ try {
+ p._parseObject();
Anton Muhin 2012/05/15 15:17:56 I am not sure it's valid implementation: _parseObj
hausner 2012/05/15 15:32:56 Nice catch! Thank you for taking a look. I'll fix
+ assert(p.position <= p.length);
+ return p.position;
+ } catch (var e) {
+ return 0;
+ }
+ }
+
_JsonParser._internal(String json)
: json = json,
length = json.length {
« no previous file with comments | « no previous file | runtime/bin/dbg_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698