00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #if !defined( _WX_JSONWRITER_H )
00012 #define _WX_JSONWRITER_H
00013
00014 #ifdef __GNUG__
00015 #pragma interface "jsonwriter.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 #endif
00031
00032 #include "json_defs.h"
00033 #include "jsonval.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 enum {
00053 wxJSONWRITER_NONE = 0,
00054 wxJSONWRITER_STYLED = 1,
00055 wxJSONWRITER_WRITE_COMMENTS = 2,
00056 wxJSONWRITER_COMMENTS_BEFORE = 4,
00057 wxJSONWRITER_COMMENTS_AFTER = 8,
00058 wxJSONWRITER_SPLIT_STRING = 16,
00059 wxJSONWRITER_NO_LINEFEEDS = 32,
00060 wxJSONWRITER_ESCAPE_SOLIDUS = 64,
00061 wxJSONWRITER_MULTILINE_STRING = 128,
00062 wxJSONWRITER_RECOGNIZE_UNSIGNED = 256,
00063 wxJSONWRITER_TAB_INDENT = 512,
00064 wxJSONWRITER_NO_INDENTATION = 1024,
00065 wxJSONWRITER_NOUTF8_STREAM = 2048,
00066 };
00067
00068
00069
00070 class WXDLLIMPEXP_JSON wxJSONWriter
00071 {
00072 public:
00073 wxJSONWriter( int style = wxJSONWRITER_STYLED, int indent = 0, int step = 3 );
00074 ~wxJSONWriter();
00075
00076 void Write( const wxJSONValue& value, wxString& str );
00077 void Write( const wxJSONValue& value, wxOutputStream& os );
00078
00079 protected:
00080
00081
00082 int DoWrite( wxOutputStream& os, const wxJSONValue& value, const wxString* key, bool comma );
00083 int WriteIndent( wxOutputStream& os );
00084 int WriteIndent( wxOutputStream& os, int num );
00085 bool IsSpace( wxChar ch );
00086 bool IsPunctuation( wxChar ch );
00087
00088 int WriteString( wxOutputStream& os, const wxString& str );
00089 int WriteStringValue( wxOutputStream& os, const wxString& str );
00090 int WriteNullValue( wxOutputStream& os );
00091 int WriteIntValue( wxOutputStream& os, const wxJSONValue& v );
00092 int WriteUIntValue( wxOutputStream& os, const wxJSONValue& v );
00093 int WriteBoolValue( wxOutputStream& os, const wxJSONValue& v );
00094 int WriteDoubleValue( wxOutputStream& os, const wxJSONValue& v );
00095
00096
00097 int WriteInvalid( wxOutputStream& os );
00098 int WriteSeparator( wxOutputStream& os );
00099
00100 int WriteKey( wxOutputStream& os, const wxString& key );
00101 int WriteComment( wxOutputStream& os, const wxJSONValue& value, bool indent );
00102
00103
00104
00105
00106 int WriteError( const wxString& err );
00107
00108 private:
00110 int m_style;
00111
00113 int m_indent;
00114
00116 int m_step;
00117
00119 int m_level;
00120
00121
00122 int m_lineNo;
00123
00124
00125 int m_colNo;
00126
00127
00128 bool m_noUtf8;
00129 };
00130
00131
00132 #endif // not defined _WX_JSONWRITER_H
00133
00134
00135