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_NOUTF8_STREAM = 64,
00047
00048 wxJSONREADER_TOLERANT = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_CASE |
00049 wxJSONREADER_MISSING | wxJSONREADER_MULTISTRING,
00050 wxJSONREADER_COMMENTS_BEFORE = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_STORE_COMMENTS
00051 };
00052
00053
00054 class WXDLLIMPEXP_JSON wxJSONReader
00055 {
00056 public:
00057 wxJSONReader( int flags = wxJSONREADER_TOLERANT, int maxErrors = 30 );
00058 virtual ~wxJSONReader();
00059
00060 int Parse( const wxString& doc, wxJSONValue* val );
00061 int Parse( wxInputStream& doc, wxJSONValue* val );
00062
00063 int GetDepth() const;
00064 int GetErrorCount() const;
00065 int GetWarningCount() const;
00066 const wxArrayString& GetErrors() const;
00067 const wxArrayString& GetWarnings() const;
00068
00069 static int UTF8NumBytes( char ch );
00070
00071 #if defined( wxJSON_64BIT_INT )
00072 static bool Strtoll( const wxString& str, wxInt64* i64 );
00073 static bool Strtoull( const wxString& str, wxUint64* ui64 );
00074 static bool DoStrto_ll( const wxString& str, wxUint64* ui64, wxChar* sign );
00075 #endif
00076
00077 protected:
00078
00079 int DoRead( wxInputStream& doc, wxJSONValue& val );
00080 void AddError( const wxString& descr );
00081 void AddError( const wxString& fmt, const wxString& str );
00082 void AddError( const wxString& fmt, wxChar ch );
00083 void AddWarning( int type, const wxString& descr );
00084 int GetStart( wxInputStream& is );
00085 int ReadChar( wxInputStream& is );
00086 int PeekChar( wxInputStream& is );
00087 void StoreValue( int ch, const wxString& key, wxJSONValue& value, wxJSONValue& parent );
00088 int SkipWhiteSpace( wxInputStream& is );
00089 int SkipComment( wxInputStream& is );
00090 void StoreComment( const wxJSONValue* parent );
00091 int ReadString( wxInputStream& is, wxJSONValue& val );
00092 int ReadToken( wxInputStream& is, int ch, wxString& s );
00093 int ReadValue( wxInputStream& is, int ch, wxJSONValue& val );
00094 int ReadUES( wxInputStream& is, char* uesBuffer );
00095 int AppendUES( wxMemoryBuffer& utf8Buff, const char* uesBuffer );
00096 int NumBytes( char ch );
00097 int ConvertCharByChar( wxString& s, const wxMemoryBuffer& utf8Buffer );
00098
00100 int m_flags;
00101
00103 int m_maxErrors;
00104
00106 int m_lineNo;
00107
00109 int m_colNo;
00110
00112 int m_level;
00113
00115 int m_depth;
00116
00118 wxJSONValue* m_current;
00119
00121 wxJSONValue* m_lastStored;
00122
00124 wxJSONValue* m_next;
00125
00127 wxString m_comment;
00128
00130 int m_commentLine;
00131
00133 wxArrayString m_errors;
00134
00136 wxArrayString m_warnings;
00137
00139 int m_peekChar;
00140
00142 bool m_noUtf8;
00143 };
00144
00145
00146 #endif // not defined _WX_JSONREADER_H
00147
00148