Mercurial > vim
comparison src/json.c @ 8275:ff900e499f79 v7.4.1430
commit https://github.com/vim/vim/commit/7ce686c990ea8c490d16be7f1c6bd95eb48816f9
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 27 16:33:22 2016 +0100
patch 7.4.1430
Problem: When encoding JSON, turning NaN and Infinity into null without
giving an error is not useful.
Solution: Pass NaN and Infinity on. If the receiver can't handle them it
will generate the error.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 27 Feb 2016 16:45:04 +0100 |
parents | 51ca0cee512e |
children | b8a56d4d83e0 |
comparison
equal
deleted
inserted
replaced
8274:fbf8242df3a4 | 8275:ff900e499f79 |
---|---|
25 # endif | 25 # endif |
26 # if defined(WIN32) && !defined(isnan) | 26 # if defined(WIN32) && !defined(isnan) |
27 # define isnan(x) _isnan(x) | 27 # define isnan(x) _isnan(x) |
28 # define isinf(x) (!_finite(x) && !_isnan(x)) | 28 # define isinf(x) (!_finite(x) && !_isnan(x)) |
29 # endif | 29 # endif |
30 # if defined(_MSC_VER) && !defined(INFINITY) | 30 # if !defined(INFINITY) && defined(DBL_MAX) |
31 # define INFINITY (DBL_MAX+DBL_MAX) | 31 # define INFINITY (DBL_MAX+DBL_MAX) |
32 # endif | |
33 # if !defined(NAN) && defined(INFINITY) | |
32 # define NAN (INFINITY-INFINITY) | 34 # define NAN (INFINITY-INFINITY) |
33 # endif | 35 # endif |
34 #endif | 36 #endif |
35 | 37 |
36 static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options); | 38 static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options); |
283 break; | 285 break; |
284 | 286 |
285 case VAR_FLOAT: | 287 case VAR_FLOAT: |
286 #ifdef FEAT_FLOAT | 288 #ifdef FEAT_FLOAT |
287 # if defined(HAVE_MATH_H) | 289 # if defined(HAVE_MATH_H) |
288 if ((options & JSON_JS) && isnan(val->vval.v_float)) | 290 if (isnan(val->vval.v_float)) |
289 ga_concat(gap, (char_u *)"NaN"); | 291 ga_concat(gap, (char_u *)"NaN"); |
290 else if ((options & JSON_JS) && isinf(val->vval.v_float)) | 292 else if (isinf(val->vval.v_float)) |
291 ga_concat(gap, (char_u *)"Infinity"); | 293 ga_concat(gap, (char_u *)"Infinity"); |
292 else if (isnan(val->vval.v_float) || isinf(val->vval.v_float)) | |
293 ga_concat(gap, (char_u *)"null"); | |
294 else | 294 else |
295 # endif | 295 # endif |
296 { | 296 { |
297 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", | 297 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", |
298 val->vval.v_float); | 298 val->vval.v_float); |