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

Side by Side Diff: runtime/platform/json.h

Issue 10357003: Beginnings of a debugger wire protocol (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/platform/json.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 #ifndef PLATFORM_JSON_H_
6 #define PLATFORM_JSON_H_
7
8 #include "vm/allocation.h"
9 #include "vm/globals.h"
10
11 namespace dart {
12
13
14 // A low level interface to tokenize JSON strings.
15 class JSONScanner : ValueObject {
16 public:
17 enum Token {
18 TokenIllegal = 0,
19 TokenLBrace,
20 TokenRBrace,
21 TokenLBrack,
22 TokenRBrack,
23 TokenColon,
24 TokenComma,
25 TokenString,
26 TokenInteger,
27 TokenTrue,
28 TokenFalse,
29 TokenNull,
30 TokenEOM
31 };
32 explicit JSONScanner(const char* json_text);
33
34 void SetText(const char* json_text);
35 void Scan();
36 Token CurrentToken() const { return token_; }
37 bool EOM() const { return token_ == TokenEOM; }
38 const char* TokenChars() const { return token_start_; }
39 int TokenLen() const { return token_length_; }
40 bool IsStringLiteral(const char* literal) const;
41 void Skip(Token matching_token);
42
43 private:
44 bool IsLetter(char ch) const;
45 bool IsDigit(char ch) const;
46 bool IsLiteral(const char* literal);
47 void ScanNumber();
48 void ScanString();
49 void Recognize(Token t);
50
51 const char* current_pos_;
52 const char* token_start_;
53 int token_length_;
54 Token token_;
55 };
56
57
58 // JSONReader is a higher level interface that allows for lookup of
59 // name-value pairs in JSON objects.
60 class JSONReader : ValueObject {
61 public:
62 enum JSONType {
63 kString,
64 kInteger,
65 kObject,
66 kArray,
67 kLiteral,
68 kNone
69 };
70
71 explicit JSONReader(const char* json_object);
72 void Set(const char* json_object);
73
74 // Returns true if a pair with the given name was found.
75 bool Seek(const char* name);
76
77 // Returns true if a syntax error was found.
78 bool Error() const { return error_; }
79
80 // Returns a pointer to the matching closing brace if the text starts
81 // with a valid JSON object. Returns NULL otherwise.
82 const char* EndOfObject();
83
84 JSONType Type() const;
85 const char* ValueChars() const {
86 return (Type() != kNone) ? scanner_.TokenChars() : NULL;
87 }
88 int ValueLen() const {
89 return (Type() != kNone) ? scanner_.TokenLen() : 0;
90 }
91 bool IsStringLiteral(const char* literal) const {
92 return scanner_.IsStringLiteral(literal);
93 }
94 bool IsTrue() const {
95 return scanner_.CurrentToken() == JSONScanner::TokenTrue;
96 }
97 bool IsFalse() const {
98 return scanner_.CurrentToken() == JSONScanner::TokenFalse;
99 }
100 bool IsNull() const {
101 return scanner_.CurrentToken() == JSONScanner::TokenNull;
102 }
103
104 private:
105 JSONScanner scanner_;
106 const char* json_object_;
107 bool error_;
108 };
109
110
111 // TextBuffer maintains a dynamic character buffer with a printf-style way to
112 // append text.
113 class TextBuffer : ValueObject {
114 public:
115 explicit TextBuffer(intptr_t buf_size);
116 ~TextBuffer();
117
118 intptr_t Printf(const char* format, ...);
119 void Clear();
120
121 char* buf() { return buf_; }
122 intptr_t length() { return msg_len_; }
123
124 private:
125 void GrowBuffer(intptr_t len);
126 char* buf_;
127 intptr_t buf_size_;
128 intptr_t msg_len_;
129 };
130
131 } // namespace dart
132
133 #endif // PLATFORM_JSON_H_
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/platform/json.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698