| 205 return value->type == CX_JSON_STRING; |
205 return value->type == CX_JSON_STRING; |
| 206 } |
206 } |
| 207 |
207 |
| 208 __attribute__((__nonnull__)) |
208 __attribute__((__nonnull__)) |
| 209 static inline bool cxJsonIsNumber(CxJsonValue *value) { |
209 static inline bool cxJsonIsNumber(CxJsonValue *value) { |
| 210 // TODO: this is not good, because an integer is also a number |
210 return value->type == CX_JSON_NUMBER || value->type == CX_JSON_INTEGER; |
| 211 return value->type == CX_JSON_NUMBER; |
|
| 212 } |
211 } |
| 213 |
212 |
| 214 __attribute__((__nonnull__)) |
213 __attribute__((__nonnull__)) |
| 215 static inline bool cxJsonIsInteger(CxJsonValue *value) { |
214 static inline bool cxJsonIsInteger(CxJsonValue *value) { |
| 216 return value->type == CX_JSON_INTEGER; |
215 return value->type == CX_JSON_INTEGER; |
| 239 __attribute__((__nonnull__)) |
238 __attribute__((__nonnull__)) |
| 240 static inline bool cxJsonIsNull(CxJsonValue *value) { |
239 static inline bool cxJsonIsNull(CxJsonValue *value) { |
| 241 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_NULL; |
240 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_NULL; |
| 242 } |
241 } |
| 243 |
242 |
| 244 __attribute__((__nonnull__)) |
243 __attribute__((__nonnull__, __returns_nonnull__)) |
| 245 static inline cxmutstr cxJsonAsString(CxJsonValue *value) { |
244 static inline char *cxJsonAsString(CxJsonValue *value) { |
| 246 // TODO: do we need a separate method to return this directly as cxstring? |
245 return value->value.string.ptr; |
| |
246 } |
| |
247 |
| |
248 __attribute__((__nonnull__)) |
| |
249 static inline cxstring cxJsonAsCxString(CxJsonValue *value) { |
| |
250 return cx_strcast(value->value.string); |
| |
251 } |
| |
252 |
| |
253 __attribute__((__nonnull__)) |
| |
254 static inline cxmutstr cxJsonAsCxMutStr(CxJsonValue *value) { |
| 247 return value->value.string; |
255 return value->value.string; |
| 248 } |
256 } |
| 249 |
257 |
| 250 __attribute__((__nonnull__)) |
258 __attribute__((__nonnull__)) |
| 251 static inline double cxJsonAsDouble(CxJsonValue *value) { |
259 static inline double cxJsonAsDouble(CxJsonValue *value) { |
| 252 return value->value.number; |
260 if (value->type == CX_JSON_INTEGER) { |
| |
261 return (double) value->value.integer; |
| |
262 } else { |
| |
263 return value->value.number; |
| |
264 } |
| 253 } |
265 } |
| 254 |
266 |
| 255 __attribute__((__nonnull__)) |
267 __attribute__((__nonnull__)) |
| 256 static inline int64_t cxJsonAsInteger(CxJsonValue *value) { |
268 static inline int64_t cxJsonAsInteger(CxJsonValue *value) { |
| 257 return value->value.integer; |
269 if (value->type == CX_JSON_INTEGER) { |
| |
270 return value->value.integer; |
| |
271 } else { |
| |
272 return (int64_t) value->value.number; |
| |
273 } |
| 258 } |
274 } |
| 259 |
275 |
| 260 __attribute__((__nonnull__)) |
276 __attribute__((__nonnull__)) |
| 261 static inline bool cxJsonAsBool(CxJsonValue *value) { |
277 static inline bool cxJsonAsBool(CxJsonValue *value) { |
| 262 return value->value.literal == CX_JSON_TRUE; |
278 return value->value.literal == CX_JSON_TRUE; |