Skip to content

Commit b4223fe

Browse files
committed
adding default optional args to get by path routines
See #208. Not finished.
1 parent 662133b commit b4223fe

File tree

3 files changed

+167
-205
lines changed

3 files changed

+167
-205
lines changed

src/json_get_scalar_by_path.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
type(json_value),pointer :: p
2+
3+
if (present(default)) then
4+
value = default
5+
else
6+
value = default_if_not_specified
7+
end if
8+
9+
if ( json%exception_thrown ) then
10+
call flag_not_found(found)
11+
return
12+
end if
13+
14+
nullify(p)
15+
call json%get(me=me, path=path, p=p)
16+
17+
if (.not. associated(p)) then
18+
call json%throw_exception('Error in '//routine//':'//&
19+
' Unable to resolve path: '// trim(path),found)
20+
else
21+
call json%get(p,value)
22+
end if
23+
24+
if ( json%exception_thrown ) then
25+
if ( present(found) .or. present(default)) then
26+
call flag_not_found(found)
27+
if (present(default)) value = default
28+
call json%clear_exceptions()
29+
end if
30+
else
31+
if ( present(found) ) found = .true.
32+
end if

src/json_get_vec_by_path.inc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
type(json_value),pointer :: p
2+
3+
if ( json%exception_thrown ) then
4+
if (present(default)) vec = default
5+
call flag_not_found(found)
6+
return
7+
end if
8+
9+
nullify(p)
10+
call json%get(me=me, path=path, p=p)
11+
12+
if (.not. associated(p)) then
13+
call json%throw_exception('Error in '//routine//':'//&
14+
' Unable to resolve path: '// trim(path),found)
15+
else
16+
call json%get(p,vec)
17+
end if
18+
19+
if ( json%exception_thrown ) then
20+
if ( present(found) .or. present(default)) then
21+
call flag_not_found(found)
22+
if (present(default)) vec = default
23+
call json%clear_exceptions()
24+
end if
25+
else
26+
if ( present(found) ) found = .true.
27+
end if

0 commit comments

Comments
 (0)