Skip to content

Commit dea69cc

Browse files
committed
Update the parameter names of json.search() and json.replace() and README.md
1 parent d0a6cc7 commit dea69cc

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and import it with:
1010
import json
1111
```
1212

13-
## Dictionary operations
13+
## Dictionary Operations
1414

1515
### list json.keys(dict d)
1616

@@ -42,7 +42,7 @@ kaos> json.flip(a)
4242
{'1': 'a', '2': 'b', '3': 'c'}
4343
```
4444

45-
## JSON related
45+
## JSON Related
4646

4747
### str json.encode(dict d)
4848

@@ -68,9 +68,9 @@ kaos> json_decoded
6868

6969
## Searching & Replacing
7070

71-
### str json.search(dict d, any x)
71+
### str json.search(dict haystack, any needle)
7272

73-
Searches the dictionary `d` for a given value `x` and returns the first corresponding key if successful. Returns an empty string `""` if unsuccessful.
73+
Searches the dictionary `haystack` for a given value `needle` and returns the first corresponding key if successful. Returns an empty string `""` if unsuccessful.
7474

7575
```chaos
7676
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
@@ -83,9 +83,9 @@ kaos> json.search(c, 'jazz')
8383
8484
```
8585

86-
### dict json.replace(dict target, any needle, any replacement)
86+
### dict json.replace(dict haystack, any needle, any replacement)
8787

88-
Replaces all occurrences of the `needle` with the `replacement` in dictionary `target`.
88+
Replaces all occurrences of the `needle` with the `replacement` in dictionary `haystack`.
8989

9090
```chaos
9191
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
@@ -96,7 +96,7 @@ kaos> json.replace(b, 'bar', 'gar')
9696
{'a': 'foo', 'b': 'gar', 'c': 'baz'}
9797
```
9898

99-
## Information functions
99+
## Information Functions
100100

101101
### num json.count(dict d)
102102

json.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "Chaos.h"
55

66

7-
// Dictionary operations
7+
// Dictionary Operations
88

99
// list json.keys(dict d)
1010

@@ -106,7 +106,8 @@ int KAOS_EXPORT Kaos_flip()
106106
return 0;
107107
}
108108

109-
// JSON related
109+
110+
// JSON Related
110111

111112
// str json.encode(dict d)
112113

@@ -141,13 +142,14 @@ int KAOS_EXPORT Kaos_decode()
141142
return 0;
142143
}
143144

145+
144146
// Searching & Replacing
145147

146-
// str json.search(dict d, any x)
148+
// str json.search(dict haystack, any needle)
147149

148150
char *search_params_name[] = {
149-
"d",
150-
"x"
151+
"haystack",
152+
"needle"
151153
};
152154
unsigned search_params_type[] = {
153155
K_DICT,
@@ -217,10 +219,10 @@ int KAOS_EXPORT Kaos_search()
217219
return 0;
218220
}
219221

220-
// dict json.replace(dict target, any needle, any replacement)
222+
// dict json.replace(dict haystack, any needle, any replacement)
221223

222224
char *replace_params_name[] = {
223-
"target",
225+
"haystack",
224226
"needle",
225227
"replacement"
226228
};
@@ -299,7 +301,8 @@ int KAOS_EXPORT Kaos_replace()
299301
return 0;
300302
}
301303

302-
// Information functions
304+
305+
// Information Functions
303306

304307
// num json.count(dict d)
305308

@@ -321,20 +324,20 @@ int KAOS_EXPORT KaosRegister(struct Kaos _kaos)
321324
{
322325
kaos = _kaos;
323326

324-
// Dictionary operations
327+
// Dictionary Operations
325328
kaos.defineFunction("keys", K_LIST, K_ANY, keys_params_name, keys_params_type, keys_params_length);
326329
kaos.defineFunction("values", K_LIST, K_ANY, values_params_name, values_params_type, values_params_length);
327330
kaos.defineFunction("flip", K_DICT, K_ANY, flip_params_name, flip_params_type, flip_params_length);
328331

329-
// JSON related
332+
// JSON Related
330333
kaos.defineFunction("encode", K_STRING, K_ANY, encode_params_name, encode_params_type, encode_params_length);
331334
kaos.defineFunction("decode", K_DICT, K_ANY, decode_params_name, decode_params_type, decode_params_length);
332335

333336
// Searching & Replacing
334337
kaos.defineFunction("search", K_STRING, K_ANY, search_params_name, search_params_type, search_params_length);
335338
kaos.defineFunction("replace", K_DICT, K_ANY, replace_params_name, replace_params_type, replace_params_length);
336339

337-
// Information functions
340+
// Information Functions
338341
kaos.defineFunction("count", K_NUMBER, K_ANY, count_params_name, count_params_type, count_params_length);
339342

340343
return 0;

test.kaos

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import json
22

3+
// Dictionary Operations
34
dict a = {'a': 1, 'b': 2, 'c': 3}
45
print json.keys(a)
56
print json.values(a)
67
print json.flip(a)
78

9+
// JSON Related
810
str json_encoded = json.encode(a)
911
print json_encoded
10-
1112
str b = '{"d": 4, "e": 5, "f": 6}'
1213
dict json_decoded = json.decode(b)
1314
print json_decoded
1415

16+
// Searching & Replacing
1517
print json.search(a, 2)
1618
dict c = {'a': 'foo', 'b': 'bar', 'c': 'baz'}
1719
print json.search(c, 'baz')
1820
print json.search(c, 'jazz')
19-
2021
print json.replace(a, 2, 9)
2122
print json.replace(c, 'bar', 'gar')
2223

24+
// Information Functions
2325
print json.count(a)

0 commit comments

Comments
 (0)