| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 #ifndef PLATFORM_JSON_H_ | 5 #ifndef PLATFORM_JSON_H_ |
| 6 #define PLATFORM_JSON_H_ | 6 #define PLATFORM_JSON_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // with a valid JSON object. Returns NULL otherwise. | 81 // with a valid JSON object. Returns NULL otherwise. |
| 82 const char* EndOfObject(); | 82 const char* EndOfObject(); |
| 83 | 83 |
| 84 JSONType Type() const; | 84 JSONType Type() const; |
| 85 const char* ValueChars() const { | 85 const char* ValueChars() const { |
| 86 return (Type() != kNone) ? scanner_.TokenChars() : NULL; | 86 return (Type() != kNone) ? scanner_.TokenChars() : NULL; |
| 87 } | 87 } |
| 88 int ValueLen() const { | 88 int ValueLen() const { |
| 89 return (Type() != kNone) ? scanner_.TokenLen() : 0; | 89 return (Type() != kNone) ? scanner_.TokenLen() : 0; |
| 90 } | 90 } |
| 91 void GetValueChars(char* buf, intptr_t buflen) const; |
| 91 bool IsStringLiteral(const char* literal) const { | 92 bool IsStringLiteral(const char* literal) const { |
| 92 return scanner_.IsStringLiteral(literal); | 93 return scanner_.IsStringLiteral(literal); |
| 93 } | 94 } |
| 94 bool IsTrue() const { | 95 bool IsTrue() const { |
| 95 return scanner_.CurrentToken() == JSONScanner::TokenTrue; | 96 return scanner_.CurrentToken() == JSONScanner::TokenTrue; |
| 96 } | 97 } |
| 97 bool IsFalse() const { | 98 bool IsFalse() const { |
| 98 return scanner_.CurrentToken() == JSONScanner::TokenFalse; | 99 return scanner_.CurrentToken() == JSONScanner::TokenFalse; |
| 99 } | 100 } |
| 100 bool IsNull() const { | 101 bool IsNull() const { |
| 101 return scanner_.CurrentToken() == JSONScanner::TokenNull; | 102 return scanner_.CurrentToken() == JSONScanner::TokenNull; |
| 102 } | 103 } |
| 103 | 104 |
| 104 private: | 105 private: |
| 105 JSONScanner scanner_; | 106 JSONScanner scanner_; |
| 106 const char* json_object_; | 107 const char* json_object_; |
| 107 bool error_; | 108 bool error_; |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 | 111 |
| 111 // TextBuffer maintains a dynamic character buffer with a printf-style way to | 112 // TextBuffer maintains a dynamic character buffer with a printf-style way to |
| 112 // append text. | 113 // append text. |
| 113 class TextBuffer : ValueObject { | 114 class TextBuffer : ValueObject { |
| 114 public: | 115 public: |
| 115 explicit TextBuffer(intptr_t buf_size); | 116 explicit TextBuffer(intptr_t buf_size); |
| 116 ~TextBuffer(); | 117 ~TextBuffer(); |
| 117 | 118 |
| 118 intptr_t Printf(const char* format, ...); | 119 intptr_t Printf(const char* format, ...); |
| 120 intptr_t Printf(const char* format, va_list args); |
| 121 |
| 119 void Clear(); | 122 void Clear(); |
| 120 | 123 |
| 121 char* buf() { return buf_; } | 124 char* buf() { return buf_; } |
| 122 intptr_t length() { return msg_len_; } | 125 intptr_t length() { return msg_len_; } |
| 123 | 126 |
| 124 private: | 127 private: |
| 125 void GrowBuffer(intptr_t len); | 128 void GrowBuffer(intptr_t len); |
| 126 char* buf_; | 129 char* buf_; |
| 127 intptr_t buf_size_; | 130 intptr_t buf_size_; |
| 128 intptr_t msg_len_; | 131 intptr_t msg_len_; |
| 129 }; | 132 }; |
| 130 | 133 |
| 131 } // namespace dart | 134 } // namespace dart |
| 132 | 135 |
| 133 #endif // PLATFORM_JSON_H_ | 136 #endif // PLATFORM_JSON_H_ |
| OLD | NEW |