@@ -94,167 +94,32 @@ class Extension
9494#endif
9595
9696 // Actions
97- void LoadJSON (TCHAR const *JSON, int flags)
98- {
99- json_settings settings = {0 };
100- settings.settings = (flags ? json_relaxed_commas : 0 );
101- char Error[128 ];
102- #ifdef UNICODE
103- std::string json = UTF8fromUnicode (JSON);
104- if (json.empty ())
105- {
106- error = L" Could not convert Unicode JSON to UTF8" ;
107- Runtime.GenerateEvent (0 );
108- error.clear ();
109- return ;
110- }
111- json_value *temp = json_parse_ex (&settings, json.c_str (), json.length (), Error);
112- #else
113- json_value *temp = json_parse_ex (&settings, JSON, strlen (JSON), Error);
114- #endif
115- if (!temp)
116- {
117- TCHAR *t = 0 ;
118- error = (t = Edif::ConvertString (Error));
119- Edif::FreeString (t), t = 0 ;
120- Runtime.GenerateEvent (0 );
121- error.clear ();
122- return ;
123- }
124- if (root)
125- {
126- current = 0 ;
127- json_value_free (root);
128- }
129- current = root = temp;
130- }
131- void EnterObject (TCHAR const *Name)
132- {
133- if (IsObject ())
134- {
135- json_value const *temp = &((*current)[UTF8fromUnicode (Name).c_str ()]);
136- if (temp)
137- {
138- current = temp;
139- }
140- }
141- }
142- void EnterArray (unsigned index)
143- {
144- if (IsArray ())
145- {
146- json_value const *temp = &((*current)[index]);
147- if (temp)
148- {
149- current = temp;
150- }
151- }
152- }
153- void GoUp ()
154- {
155- current = current->parent ? current->parent : current;
156- }
157- void GotoRoot ()
158- {
159- current = root;
160- }
97+ void LoadJSON (TCHAR const *JSON, int flags);
98+ void EnterObject (TCHAR const *Name);
99+ void EnterArray (unsigned index);
100+ void GoUp ();
101+ void GotoRoot ();
161102
162103 // Conditions
163- bool OnError () // 0
164- {
165- return true ;
166- }
167- bool IsString ()
168- {
169- return current->type == json_string;
170- }
171- bool IsInteger ()
172- {
173- return current->type == json_integer;
174- }
175- bool IsDouble ()
176- {
177- return current->type == json_double;
178- }
179- bool IsObject ()
180- {
181- return current->type == json_object;
182- }
183- bool IsArray ()
184- {
185- return current->type == json_array;
186- }
187- bool IsBoolean ()
188- {
189- return current->type == json_boolean;
190- }
191- bool IsNull ()
192- {
193- return current->type == json_null;
194- }
195- bool IsTrue ()
196- {
197- return IsBoolean () && current->u .boolean ;
198- }
104+ bool OnError (); // 0
105+ bool IsString ();
106+ bool IsInteger ();
107+ bool IsDouble ();
108+ bool IsObject ();
109+ bool IsArray ();
110+ bool IsBoolean ();
111+ bool IsNull ();
112+ bool IsTrue ();
199113
200114 // Expressions
201- TCHAR const *GetError ()
202- {
203- return Runtime.CopyString (error.c_str ());
204- }
205- TCHAR const *GetString ()
206- {
207- if (!IsString ()) return _T (" " );
208- TCHAR *t = Edif::ConvertString (current->u .string .ptr );
209- TCHAR *c = Runtime.CopyString (t);
210- Edif::FreeString (t);
211- return c;
212- }
213- int GetInteger ()
214- {
215- return IsInteger () ? static_cast <int >(current->u .integer ) : 0 ;
216- }
217- TCHAR const *GetLong ()
218- {
219- if (IsInteger ())
220- {
221- std::basic_ostringstream<TCHAR> ss;
222- ss << current->u .integer ;
223- return Runtime.CopyString (ss.str ().c_str ());
224- }
225- return _T (" 0" );
226- }
227- float GetFloat ()
228- {
229- return IsDouble () ? static_cast <float >(current->u .dbl ) : 0 .0f ;
230- }
231- TCHAR const *GetDouble ()
232- {
233- if (IsDouble ())
234- {
235- std::basic_ostringstream<TCHAR> ss;
236- ss << std::setprecision (20 ) << current->u .dbl ;
237- return Runtime.CopyString (ss.str ().c_str ());
238- }
239- return _T (" 0.0" );
240- }
241- unsigned GetNumValues ()
242- {
243- if (IsObject ())
244- {
245- return current->u .object .length ;
246- }
247- else if (IsArray ())
248- {
249- return current->u .array .length ;
250- }
251- return 0 ;
252- }
253- unsigned GetBoolNum ()
254- {
255- return IsBoolean () ? (current->u .boolean ? 1 : 0 ) : 0 ;
256- }
257-
115+ TCHAR const *GetError ();
116+ TCHAR const *GetString ();
117+ int GetInteger ();
118+ TCHAR const *GetLong ();
119+ float GetFloat ();
120+ TCHAR const *GetDouble ();
121+ unsigned GetNumValues ();
122+ unsigned GetBoolNum ();
258123
259124
260125 short Handle (); // defined & documented in Extension.cpp
0 commit comments