Skip to content

Commit 7823a3b

Browse files
committed
patch 7.4.1304
Problem: Function names are difficult to read. Solution: Rename jsonencode to json_encode, jsondecode to json_decode, jsencode to js_encode and jsdecode to js_decode.
1 parent b6a4fee commit 7823a3b

4 files changed

Lines changed: 182 additions & 178 deletions

File tree

runtime/doc/eval.txt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ delete( {fname} [, {flags}]) Number delete the file or directory {fname}
18461846
did_filetype() Number TRUE if FileType autocommand event used
18471847
diff_filler( {lnum}) Number diff filler lines about {lnum}
18481848
diff_hlID( {lnum}, {col}) Number diff highlighting at {lnum}/{col}
1849+
disable_char_avail_for_testing({expr}) none test without typeahead
18491850
empty( {expr}) Number TRUE if {expr} is empty
18501851
escape( {string}, {chars}) String escape {chars} in {string} with '\'
18511852
eval( {string}) any evaluate {string} into its value
@@ -1952,14 +1953,14 @@ invert( {expr}) Number bitwise invert
19521953
isdirectory( {directory}) Number TRUE if {directory} is a directory
19531954
islocked( {expr}) Number TRUE if {expr} is locked
19541955
items( {dict}) List key-value pairs in {dict}
1955-
job_start({command} [, {options}]) Job start a job
1956-
job_status({job}) String get the status of a job
1957-
job_stop({job} [, {how}]) Number stop a job
1956+
job_start( {command} [, {options}]) Job start a job
1957+
job_status( {job}) String get the status of a job
1958+
job_stop( {job} [, {how}]) Number stop a job
19581959
join( {list} [, {sep}]) String join {list} items into one String
1959-
jsdecode( {string}) any decode JS style JSON
1960-
jsencode( {expr}) String encode JS style JSON
1961-
jsondecode( {string}) any decode JSON
1962-
jsonencode( {expr}) String encode JSON
1960+
js_decode( {string}) any decode JS style JSON
1961+
js_encode( {expr}) String encode JS style JSON
1962+
json_decode( {string}) any decode JSON
1963+
json_encode( {expr}) String encode JSON
19631964
keys( {dict}) List keys in {dict}
19641965
len( {expr}) Number the length of {expr}
19651966
libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
@@ -2733,8 +2734,9 @@ copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
27332734
When {expr} is a |List| a shallow copy is created. This means
27342735
that the original |List| can be changed without changing the
27352736
copy, and vice versa. But the items are identical, thus
2736-
changing an item changes the contents of both |Lists|. Also
2737-
see |deepcopy()|.
2737+
changing an item changes the contents of both |Lists|.
2738+
A |Dictionary| is copied in a similar way as a |List|.
2739+
Also see |deepcopy()|.
27382740

27392741
cos({expr}) *cos()*
27402742
Return the cosine of {expr}, measured in radians, as a |Float|.
@@ -4386,30 +4388,30 @@ join({list} [, {sep}]) *join()*
43864388
converted into a string like with |string()|.
43874389
The opposite function is |split()|.
43884390

4389-
jsdecode({string}) *jsdecode()*
4390-
This is similar to |jsondecode()| with these differences:
4391+
js_decode({string}) *js_decode()*
4392+
This is similar to |json_decode()| with these differences:
43914393
- Object key names do not have to be in quotes.
43924394
- Empty items in an array (between two commas) are allowed and
43934395
result in v:none items.
43944396

4395-
jsencode({expr}) *jsencode()*
4396-
This is similar to |jsonencode()| with these differences:
4397+
js_encode({expr}) *js_encode()*
4398+
This is similar to |json_encode()| with these differences:
43974399
- Object key names are not in quotes.
43984400
- v:none items in an array result in an empty item between
43994401
commas.
44004402
For example, the Vim object:
4401-
[1,v:none,{"one":1}],v:none ~
4403+
[1,v:none,{"one":1},v:none] ~
44024404
Will be encoded as:
44034405
[1,,{one:1},,] ~
4404-
While jsonencode() would produce:
4406+
While json_encode() would produce:
44054407
[1,null,{"one":1},null] ~
44064408
This encoding is valid for JavaScript. It is more efficient
44074409
than JSON, especially when using an array with optional items.
44084410

44094411

4410-
jsondecode({string}) *jsondecode()*
4412+
json_decode({string}) *json_decode()*
44114413
This parses a JSON formatted string and returns the equivalent
4412-
in Vim values. See |jsonencode()| for the relation between
4414+
in Vim values. See |json_encode()| for the relation between
44134415
JSON and Vim values.
44144416
The decoding is permissive:
44154417
- A trailing comma in an array and object is ignored.
@@ -4419,7 +4421,7 @@ jsondecode({string}) *jsondecode()*
44194421
- An empty object member name is not allowed.
44204422
- Duplicate object member names are not allowed.
44214423

4422-
jsonencode({expr}) *jsonencode()*
4424+
json_encode({expr}) *json_encode()*
44234425
Encode {expr} as JSON and return this as a string.
44244426
The encoding is specified in:
44254427
https://tools.ietf.org/html/rfc7159.html

src/eval.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,10 @@ static void f_job_stop(typval_T *argvars, typval_T *rettv);
629629
static void f_job_status(typval_T *argvars, typval_T *rettv);
630630
#endif
631631
static void f_join(typval_T *argvars, typval_T *rettv);
632-
static void f_jsdecode(typval_T *argvars, typval_T *rettv);
633-
static void f_jsencode(typval_T *argvars, typval_T *rettv);
634-
static void f_jsondecode(typval_T *argvars, typval_T *rettv);
635-
static void f_jsonencode(typval_T *argvars, typval_T *rettv);
632+
static void f_js_decode(typval_T *argvars, typval_T *rettv);
633+
static void f_js_encode(typval_T *argvars, typval_T *rettv);
634+
static void f_json_decode(typval_T *argvars, typval_T *rettv);
635+
static void f_json_encode(typval_T *argvars, typval_T *rettv);
636636
static void f_keys(typval_T *argvars, typval_T *rettv);
637637
static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv);
638638
static void f_len(typval_T *argvars, typval_T *rettv);
@@ -8213,10 +8213,10 @@ static struct fst
82138213
{"job_stop", 1, 2, f_job_stop},
82148214
#endif
82158215
{"join", 1, 2, f_join},
8216-
{"jsdecode", 1, 1, f_jsdecode},
8217-
{"jsencode", 1, 1, f_jsencode},
8218-
{"jsondecode", 1, 1, f_jsondecode},
8219-
{"jsonencode", 1, 1, f_jsonencode},
8216+
{"js_decode", 1, 1, f_js_decode},
8217+
{"js_encode", 1, 1, f_js_encode},
8218+
{"json_decode", 1, 1, f_json_decode},
8219+
{"json_encode", 1, 1, f_json_encode},
82208220
{"keys", 1, 1, f_keys},
82218221
{"last_buffer_nr", 0, 0, f_last_buffer_nr},/* obsolete */
82228222
{"len", 1, 1, f_len},
@@ -14488,10 +14488,10 @@ f_join(typval_T *argvars, typval_T *rettv)
1448814488
}
1448914489

1449014490
/*
14491-
* "jsdecode()" function
14491+
* "js_decode()" function
1449214492
*/
1449314493
static void
14494-
f_jsdecode(typval_T *argvars, typval_T *rettv)
14494+
f_js_decode(typval_T *argvars, typval_T *rettv)
1449514495
{
1449614496
js_read_T reader;
1449714497

@@ -14503,20 +14503,20 @@ f_jsdecode(typval_T *argvars, typval_T *rettv)
1450314503
}
1450414504

1450514505
/*
14506-
* "jsencode()" function
14506+
* "js_encode()" function
1450714507
*/
1450814508
static void
14509-
f_jsencode(typval_T *argvars, typval_T *rettv)
14509+
f_js_encode(typval_T *argvars, typval_T *rettv)
1451014510
{
1451114511
rettv->v_type = VAR_STRING;
1451214512
rettv->vval.v_string = json_encode(&argvars[0], JSON_JS);
1451314513
}
1451414514

1451514515
/*
14516-
* "jsondecode()" function
14516+
* "json_decode()" function
1451714517
*/
1451814518
static void
14519-
f_jsondecode(typval_T *argvars, typval_T *rettv)
14519+
f_json_decode(typval_T *argvars, typval_T *rettv)
1452014520
{
1452114521
js_read_T reader;
1452214522

@@ -14528,10 +14528,10 @@ f_jsondecode(typval_T *argvars, typval_T *rettv)
1452814528
}
1452914529

1453014530
/*
14531-
* "jsonencode()" function
14531+
* "json_encode()" function
1453214532
*/
1453314533
static void
14534-
f_jsonencode(typval_T *argvars, typval_T *rettv)
14534+
f_json_encode(typval_T *argvars, typval_T *rettv)
1453514535
{
1453614536
rettv->v_type = VAR_STRING;
1453714537
rettv->vval.v_string = json_encode(&argvars[0], 0);

0 commit comments

Comments
 (0)