00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #if !defined( _WX_JSONREADER_H )
00012 #define _WX_JSONREADER_H
00013
00014 #ifdef __GNUG__
00015 #pragma interface "jsonreader.h"
00016 #endif
00017
00018
00019 #include "wx/wxprec.h"
00020
00021 #ifdef __BORLANDC__
00022 #pragma hdrstop
00023 #endif
00024
00025
00026
00027 #ifndef WX_PRECOMP
00028 #include <wx/stream.h>
00029 #include <wx/string.h>
00030 #include <wx/arrstr.h>
00031 #endif
00032
00033
00034 #include "json_defs.h"
00035 #include "jsonval.h"
00036
00037
00038 enum {
00039 wxJSONREADER_STRICT = 0,
00040 wxJSONREADER_ALLOW_COMMENTS = 1,
00041 wxJSONREADER_STORE_COMMENTS = 2,
00042 wxJSONREADER_CASE = 4,
00043 wxJSONREADER_MISSING = 8,
00044 wxJSONREADER_MULTISTRING = 16,
00045 wxJSONREADER_COMMENTS_AFTER = 32,
00046 wxJSONREADER_TOLERANT = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_CASE |
00047 wxJSONREADER_MISSING | wxJSONREADER_MULTISTRING,
00048 wxJSONREADER_COMMENTS_BEFORE = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_STORE_COMMENTS
00049 };
00050
00051
00052 class WXDLLIMPEXP_JSON wxJSONReader
00053 {
00054 public:
00055 wxJSONReader( int flags = wxJSONREADER_TOLERANT, int maxErrors = 30 );
00056 virtual ~wxJSONReader();
00057
00058 int Parse( const wxString& doc, wxJSONValue* val );
00059 int Parse( wxInputStream& doc, wxJSONValue* val );
00060
00061 int GetErrorCount() const;
00062 int GetWarningCount() const;
00063
00064 static int UTF8NumBytes( char ch );
00065
00066 #if defined( wxJSON_64BIT_INT )
00067 static bool Strtoll( const wxString& str, wxInt64* i64 );
00068 static bool Strtoull( const wxString& str, wxUint64* ui64 );
00069 #endif
00070
00071 const wxArrayString& GetErrors() const;
00072 const wxArrayString& GetWarnings() const;
00073
00074 protected:
00075
00076 int Parse( wxJSONValue* val );
00077 int DoRead( wxJSONValue& val );
00078 void AddError( const wxString& descr );
00079 void AddError( const wxString& fmt, const wxString& str );
00080 void AddError( const wxString& fmt, wxChar ch );
00081 void AddWarning( int type, const wxString& descr );
00082 int GetStart();
00083 int ReadChar();
00084 int GetChar();
00085 int PeekChar();
00086 void StoreValue( int ch, const wxString& key, wxJSONValue& value, wxJSONValue& parent );
00087 int SkipWhiteSpace();
00088 int SkipComment();
00089 void StoreComment( const wxJSONValue* parent );
00090 int ReadString( wxJSONValue& val );
00091 int ReadToken( int ch, wxString& s );
00092 int ReadValue( int ch, wxJSONValue& val );
00093 int ReadUnicode( long int& hex );
00094 int AppendUnicodeSequence( wxString& s, int hex );
00095 int NumBytes( char ch );
00096
00097 static bool DoStrto_ll( const wxString& str, wxUint64* ui64, wxChar* sign );
00098
00099
00100
00102 int m_flags;
00103
00105 int m_maxErrors;
00106
00107
00108
00110 int m_lineNo;
00111
00113 int m_colNo;
00114
00116 int m_level;
00117
00119 wxJSONValue* m_current;
00120
00122 wxJSONValue* m_lastStored;
00123
00125 wxJSONValue* m_next;
00126
00128 wxString m_comment;
00129
00131 int m_commentLine;
00132
00134 wxArrayString m_errors;
00135
00137 wxArrayString m_warnings;
00138
00140 int m_charPos;
00141
00143 int m_inType;
00144
00146 void* m_inObject;
00147
00149 int m_peekChar;
00150
00152
00167 wxMBConv* m_conv;
00168 };
00169
00170
00171 #endif // not defined _WX_JSONREADER_H
00172
00173