Skip to content

Commit 19beb3c

Browse files
committed
morepretty
1 parent 327ddb6 commit 19beb3c

18 files changed

+84
-85
lines changed

src/jsony.nim

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import jsony/objvar, std/strutils, std/tables, std/sets, std/unicode, std/json, std/options, std/parseutils, std/typetraits
1+
import jsony/objvar, std/json, std/options, std/parseutils, std/sets,
2+
std/strutils, std/tables, std/typetraits, std/unicode
23

34
type JsonError* = object of ValueError
45

@@ -74,10 +75,19 @@ proc parseHook*(s: string, i: var int, v: var bool) =
7475
else:
7576
# Its faster to do char by char scan:
7677
eatSpace(s, i)
77-
if i + 3 < s.len and s[i+0] == 't' and s[i+1] == 'r' and s[i+2] == 'u' and s[i+3] == 'e':
78+
if i + 3 < s.len and
79+
s[i+0] == 't' and
80+
s[i+1] == 'r' and
81+
s[i+2] == 'u' and
82+
s[i+3] == 'e':
7883
i += 4
7984
v = true
80-
elif i + 4 < s.len and s[i+0] == 'f' and s[i+1] == 'a' and s[i+2] == 'l' and s[i+3] == 's' and s[i+4] == 'e':
85+
elif i + 4 < s.len and
86+
s[i+0] == 'f' and
87+
s[i+1] == 'a' and
88+
s[i+2] == 'l' and
89+
s[i+3] == 's' and
90+
s[i+4] == 'e':
8191
i += 5
8292
v = false
8393
else:
@@ -235,7 +245,11 @@ proc parseStringFast(s: string, i: var int, v: var string) =
235245
proc parseHook*(s: string, i: var int, v: var string) =
236246
## Parse string.
237247
eatSpace(s, i)
238-
if i + 3 < s.len and s[i+0] == 'n' and s[i+1] == 'u' and s[i+2] == 'l' and s[i+3] == 'l':
248+
if i + 3 < s.len and
249+
s[i+0] == 'n' and
250+
s[i+1] == 'u' and
251+
s[i+2] == 'l' and
252+
s[i+3] == 'l':
239253
i += 4
240254
return
241255
eatChar(s, i, '"')
@@ -285,7 +299,11 @@ proc parseHook*[T: array](s: string, i: var int, v: var T) =
285299

286300
proc parseHook*[T: not object](s: string, i: var int, v: var ref T) =
287301
eatSpace(s, i)
288-
if i + 3 < s.len and s[i+0] == 'n' and s[i+1] == 'u' and s[i+2] == 'l' and s[i+3] == 'l':
302+
if i + 3 < s.len and
303+
s[i+0] == 'n' and
304+
s[i+1] == 'u' and
305+
s[i+2] == 'l' and
306+
s[i+3] == 'l':
289307
i += 4
290308
return
291309
new(v)
@@ -407,7 +425,11 @@ proc parseHook*[T: enum](s: string, i: var int, v: var T) =
407425
proc parseHook*[T: object|ref object](s: string, i: var int, v: var T) =
408426
## Parse an object or ref object.
409427
eatSpace(s, i)
410-
if i + 3 < s.len and s[i+0] == 'n' and s[i+1] == 'u' and s[i+2] == 'l' and s[i+3] == 'l':
428+
if i + 3 < s.len and
429+
s[i+0] == 'n' and
430+
s[i+1] == 'u' and
431+
s[i+2] == 'l' and
432+
s[i+3] == 'l':
411433
i += 4
412434
return
413435
eatChar(s, i, '{')
@@ -449,7 +471,11 @@ proc parseHook*[T: object|ref object](s: string, i: var int, v: var T) =
449471
proc parseHook*[T](s: string, i: var int, v: var Option[T]) =
450472
## Parse an Option.
451473
eatSpace(s, i)
452-
if i + 3 < s.len and s[i+0] == 'n' and s[i+1] == 'u' and s[i+2] == 'l' and s[i+3] == 'l':
474+
if i + 3 < s.len and
475+
s[i+0] == 'n' and
476+
s[i+1] == 'u' and
477+
s[i+2] == 'l' and
478+
s[i+3] == 'l':
453479
i += 4
454480
return
455481
var e: T
@@ -576,7 +602,7 @@ proc dumpHook*(s: var string, v: string)
576602
proc dumpHook*(s: var string, v: char)
577603
proc dumpHook*(s: var string, v: tuple)
578604
proc dumpHook*(s: var string, v: enum)
579-
type t[T] = tuple[a:string, b:T]
605+
type t[T] = tuple[a: string, b: T]
580606
proc dumpHook*[N, T](s: var string, v: array[N, t[T]])
581607
proc dumpHook*[N, T](s: var string, v: array[N, T])
582608
proc dumpHook*[T](s: var string, v: seq[T])
@@ -869,6 +895,5 @@ template toStaticJson*(v: untyped): static[string] =
869895
# const s = v.toJsonDynamic()
870896
# s
871897

872-
873898
when defined(release):
874899
{.pop.}

tests/all.nim

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,7 @@
22
# nim js -r .\tests\all.nim
33
# nim cpp -r .\tests\all.nim
44

5-
import test_arrays
6-
import test_char
7-
import test_enums
8-
import test_errors
9-
import test_fast_numbers
10-
import test_json_in_json
11-
import test_numbers
12-
import test_objects
13-
import test_options
14-
import test_parseHook
15-
import test_sets
16-
import test_strings
17-
import test_tables
18-
import test_tojson
19-
import test_tuples
20-
import test_refs
21-
import test_rawjson
22-
5+
import test_arrays, test_char, test_enums, test_errors, test_fast_numbers,
6+
test_json_in_json, test_numbers, test_objects, test_options, test_parseHook,
7+
test_rawjson, test_refs, test_sets, test_strings, test_tables, test_tojson, test_tuples
238
echo "all tests pass"

tests/bench.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import benchy, random, streams, macros
2-
import jsony, jason
3-
import eminim
1+
import benchy, eminim, jason, jsony, macros, random, streams
42
when defined(packedjson):
53
import packedjson, packedjson/deserialiser
64
else:

tests/bench_parts.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import benchy, random, streams
2-
import jsony, jason
3-
import eminim
1+
import benchy, eminim, jason, jsony, random, streams
42
when defined(packedjson):
53
import packedjson, packedjson/deserialiser
64
else:
@@ -9,7 +7,6 @@ when not defined(gcArc):
97
import serialization
108
import json_serialization except Json, toJson
119

12-
1310
block:
1411
echo "deserialize string:"
1512
var jsonStr = "\"hello there how are you?\""

tests/bench_statics.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import jsony, jason, benchy
1+
import benchy, jason, jsony
22

33
const
44
number11 = 11
@@ -57,4 +57,4 @@ timeIt "treeform/jsony object", 100:
5757

5858
timeIt "disruptek/jason object", 100:
5959
for i in 0 .. 1000:
60-
discard thing.jason.string
60+
discard thing.jason.string

tests/fuzz.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os, strutils, random, strformat, tables, jsony
2-
1+
import jsony, os, random, strformat, strutils, tables
32

43
type
54
NodeKind = enum

tests/fuzz_strings.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import random, jsony, unicode
1+
import jsony, random, unicode
22

33
randomize()
44

tests/run_extranl_suite.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import osproc, os, strutils, sequtils
1+
import os, osproc, sequtils, strutils
22

33
# https://github.com/nst/JSONTestSuite
44
# A comprehensive test suite for RFC 8259 compliant JSON parsers

tests/run_test_jsony.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Rebuild with: nim c -d:release
22

3-
import json
4-
import os
5-
3+
import json, os
64
let fn = os.paramStr(1)
75

86
try:

tests/test_json_in_json.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import jsony, json
1+
import json, jsony
22

33
block:
44
type Entry = object

0 commit comments

Comments
 (0)